Solved

C# syntax help

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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