In C #, how do you produce a field name, and then when it is serialized?

I have a WCF service that I created from XSD from a client. The XSD client invokes a field named 3rdPartyTrackingNumber. Because in C # I cannot have a field that starts with the number that I called it ThirdPartyTrackingNumber. Is there a meta tag or something that I can put in a column that will display it as 3rdartyTrackingNumber on serialization?

public class OSSShipmentGroup
{
    public string status { get; set; }
    public string shipmentNumber { get; set; }
    public object shipFrom { get; set; }
    public string carrierName { get; set; }

    [Some meta tag here]
    public string ThirdPartyTrackingNumber {get; set;}
    public OSSOrderDates dates { get; set; }
    public OSSOrderAddress[] address {get; set;}
    public OSSOrderShipmentItem[] containedItems { get; set; }
    public OSSShipmentInvoice[] invoice {get; set;}
}

I know that I can implement ISerializable and make changes to GetObjectData, but if it's only one field, I was hoping I could just add a meta tag to the field.

+3
source share
2 answers

, . , DataContractSerializer, WCF basicHttpBinding wsHttpBinding, [DataMember]

[DataMember(Name = "ABC")]
public string ThirdPartyTrackingNumber { get; set; }

XmlSerializer, [XmlElement] :

[XmlElement(ElementName = "ABC")]
public string ThirdPartyTrackingNumber { get; set; }
+6

WCF , [DataContract], [DataMember], Name="foo".

, , : " , , , .

+1

Source: https://habr.com/ru/post/1784794/


All Articles