Solved

C# syntax help

Posted on 2015-01-07
3
210 Views
Last Modified: 2015-01-07
Hello,

I am getting error on the bolded text below:

Error      2      Cannot implicitly convert type 'AAON.Shipping.EShipping.RateWs.Accessorial[]' to 'AAON.Shipping.Objects.Accessorial'      C:\AaonShippingWs\AAONShippingWs\Objects\RateRequest.cs      40      34      AAONShippingWs

can someone help with the C# syntax:

-----------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AAON.Shipping.Objects
{
    public class RateRequest
    {
               
        private System.Runtime.Serialization.ExtensionDataObject extensionDataField;      
        private Accessorial[] AccessorialsField;        
        private string AccountNumberField;      
        private string AuthenticationTokenField;        
        private bool BookableField;        
     

        public static implicit operator RateRequest(EShipping.RateWs.RateRequest data)
        {
            RateRequest ndata = new RateRequest();
            ndata.ExtensionData = data.ExtensionData;          
            ndata.Accessorials = data.Accessorials;
           ndata.AccountNumber = data.AccountNumber;
            ndata.AuthenticationToken = data.AuthenticationToken;
            ndata.Bookable = data.Bookable;          
           
            return ndata;
        }


        public static implicit operator EShipping.RateWs.RateRequest(RateRequest data)
        {
            EShipping.RateWs.RateRequest ndata = new EShipping.RateWs.RateRequest();
            ndata.ExtensionData = data.ExtensionData;
            ndata.Accessorials = data.Accessorials;
           ndata.AccountNumber = data.AccountNumber;
            ndata.AuthenticationToken = data.AuthenticationToken;
            ndata.Bookable = data.Bookable;          

            return ndata;
        }

       
        public System.Runtime.Serialization.ExtensionDataObject ExtensionData
        {
            get
            {
                return this.extensionDataField;
            }
            set
            {
                this.extensionDataField = value;
            }
        }

       
       public Accessorial[] Accessorials
        {
            get
            {
                return this.AccessorialsField;
            }
            set
            {
                if ((object.ReferenceEquals(this.AccessorialsField, value) != true))
                {
                    this.AccessorialsField = value;                    
                }
            }
        }

       
        public string AccountNumber
        {
            get
            {
                return this.AccountNumberField;
            }
            set
            {
                if ((object.ReferenceEquals(this.AccountNumberField, value) != true))
                {
                    this.AccountNumberField = value;                  
                }
            }
        }

       
        public string AuthenticationToken
        {
            get
            {
                return this.AuthenticationTokenField;
            }
            set
            {
                if ((object.ReferenceEquals(this.AuthenticationTokenField, value) != true))
                {
                    this.AuthenticationTokenField = value;                    
                }
            }
        }

       
        public bool Bookable
        {
            get
            {
                return this.BookableField;
            }
            set
            {
                if ((this.BookableField.Equals(value) != true))
                {
                    this.BookableField = value;                    
                }
            }
        }
0
Comment
Question by:mani_sai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Author Comment

by:mani_sai
ID: 40536318
Accessorial is a separate class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AAON.Shipping.Objects
{
    public class Accessorial
    {

        private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
        private string AccessorialCodeField;        
        private string AccessorialNameField;


        public static implicit operator Accessorial(EShipping.RateWs.Accessorial data)
        {
            Accessorial ndata = new Accessorial();
            ndata.ExtensionData = data.ExtensionData;
            ndata.AccessorialCode = data.AccessorialCode;
            ndata.AccessorialName = data.AccessorialName;
           
            return ndata;
        }


        public static implicit operator EShipping.RateWs.Accessorial(Accessorial data)
        {
            EShipping.RateWs.Accessorial ndata = new EShipping.RateWs.Accessorial();
            ndata.ExtensionData = data.ExtensionData;
            ndata.AccessorialCode = data.AccessorialCode;
            ndata.AccessorialName = data.AccessorialName;
                     
            return ndata;
        }

       
       
        public System.Runtime.Serialization.ExtensionDataObject ExtensionData
        {
            get
            {
                return this.extensionDataField;
            }
            set
            {
                this.extensionDataField = value;
            }
        }

       
        public string AccessorialCode
        {
            get
            {
                return this.AccessorialCodeField;
            }
            set
            {
                if ((object.ReferenceEquals(this.AccessorialCodeField, value) != true))
                {
                    this.AccessorialCodeField = value;                    
                }
            }
        }

       
        public string AccessorialName
        {
            get
            {
                return this.AccessorialNameField;
            }
            set
            {
                if ((object.ReferenceEquals(this.AccessorialNameField, value) != true))
                {
                    this.AccessorialNameField = value;                    
                }
            }
        }

    }
}
0
 
LVL 9

Accepted Solution

by:
Beartlaoi earned 500 total points
ID: 40536422
In Objects.Accessorial you have
public static implicit operator Accessorial(EShipping.RateWs.Accessorial data)

However you are assigning RateWs.Accessorial[] to an Objects.Accessorial[]
The implicit operator does not extend to use of the array of the type.
You will need to create an additional implicit operator to handle the arrays.  

        public static implicit operator Accessorial[](EShipping.RateWs.Accessorial[] adata)
        {
            int L = data.Length;
            Accessorial[] andata = new Accessorial[L];
            for( int i=0; i < L; ++i )
            {
                  EShipping.RateWs.Accessorial ndata = new EShipping.RateWs.Accessorial();
                  ndata = adata[ i ];   // this uses the original implicit operator
                  andata[ i ] = ndata;
            }
            return ndata;
        }
0
 
LVL 8

Author Closing Comment

by:mani_sai
ID: 40536617
Thank you.
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question