Solved

C# syntax help

Posted on 2015-01-07
3
204 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
  • 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Issue with SSIS module 26 104
Add a Condition in ASP Repeater 6 34
ASP Repeater control - onl;y show if flag is true 7 16
Adding items to a C# list incrementally 5 33
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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