Solved

C# syntax help

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now