?
Solved

C# syntax help

Posted on 2015-01-07
3
Medium Priority
?
219 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

719 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