I am developing an UWP app using the Creators Update SDK.
I am trying to serialize a ObservableCollection ignoring a property of their class.
Here is my code, it have my class and the methods to serialize, you can see I am using [DataContract] and [IgnoreDataMember] but it's not working.
public class Classes
{
[DataContract]
public class Car : BindableBase
{
[DataMember]
private string _Name;
public string Name
{
get { return _Name; }
set { Set(ref _Name, value); }
}
[DataMember]
private string _Brand;
public string Brand
{
get { return _Brand; }
set { Set(ref _Brand, value); }
}
[IgnoreDataMember]
private bool _Electric;
public bool Electric
{
get { return _Electric; }
set { Set(ref _Electric, value); }
}
[DataMember]
private double _Price;
public double Price
{
get { return _Price; }
set { Set(ref _Price, value); }
}
}
public class Values_Car : ObservableCollection<Car> { }
public static class Garage
{
public static Values_Car Cars = new Values_Car();
static Garage()
{
}
}
[XmlRoot("Root")]
public class GarageDTO
{
[XmlElement]
public Values_Car Cars { get { return Garage.Cars; } }
}
}
public class NewSerialization
{
private static void FillList()
{
Car e_1 = new Car()
{
Name = "element_Name",
Brand = "element_Brand",
Electric = true,
Price = 1,
};
Car e_2 = new Car()
{
Name = "element_Name",
Brand = "element_Brand",
Electric = true,
Price = 2,
};
Garage.Cars.Add(e_1);
Garage.Cars.Add(e_2);
}
public static string Serializer()
{
FillList();
var _Instance = new GarageDTO();
var serializer = new XmlSerializer(typeof(GarageDTO));
using (var stream_original = new MemoryStream())
{
serializer.Serialize(stream_original, _Instance);
string string_original = string.Empty;
stream_original.Position = 0;
using (StreamReader reader = new StreamReader(stream_original, Encoding.Unicode))
{
string_original = reader.ReadToEnd();
}
return string_original;
}
}
}
using NewSerialization.Serializer(); I got:
But in the xml I got the Electric property which is ignored.
<?xml version="1.0" encoding="utf-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Cars>
<Name>element_Name</Name>
<Brand>element_Brand</Brand>
<Electric>true</Electric>
<Price>1</Price>
</Cars>
<Cars>
<Name>element_Name</Name>
<Brand>element_Brand</Brand>
<Electric>true</Electric>
<Price>2</Price>
</Cars>
</Root>
How I can ignoring a property of my ObservableCollection on serialization?
Appreciate your help.
Thanks to the comments of #dbc and #Aluan Haddad I found the exact I was finding, this should be my class to achieve that:
public class Car : BindableBase
{
private string _Name;
public string Name
{
get { return _Name; }
set { Set(ref _Name, value); }
}
private string _Brand;
public string Brand
{
get { return _Brand; }
set { Set(ref _Brand, value); }
}
private bool _Electric;
[XmlIgnore] //<----This!
public bool Electric
{
get { return _Electric; }
set { Set(ref _Electric, value); }
}
private double _Price;
public double Price
{
get { return _Price; }
set { Set(ref _Price, value); }
}
}
Related
I have a c# class, I am creating object to put data in class , some data i have no able to do, here is my code
InvoiceType oInvoiceType = new InvoiceType(); // my main object
// using object UBLVersionIDType
UBLVersionIDType oUBLVersionIDType = new UBLVersionIDType();
IdentifierType oIdentifierType = new IdentifierType();
oIdentifierType.Value = "UBL 2.1";
//oUBLVersionIDType.schemeID = oIdentifierType.schemeID;
oUBLVersionIDType.Value = oIdentifierType.Value;
// using object InvoiceTypeCodeType
InvoiceTypeCodeType oInvoiceTypeCode = new InvoiceTypeCodeType();
CodeType oCodeType = new CodeType();
oCodeType.Value = "01";
oInvoiceTypeCode.Value = oCodeType.Value;
// using Note
NoteType oNoteType = new NoteType();
oNoteType.Value = new
TextType oTextType = new TextType(); // this show error
oTextType.Value = "This is a Note 1"; // this show error
oNoteType.Value = oTextType.Value; // this show error
// asign main object
oInvoiceType.UBLVersionID = oUBLVersionIDType;
oInvoiceType.InvoiceTypeCode = oInvoiceTypeCode;
//oInvoiceType.Note = oNoteType; // this show error !!!!!!!!
Next you can see the class
public partial class InvoiceType
{
private UBLVersionIDType uBLVersionIDField;
private InvoiceTypeCodeType invoiceTypeCodeField;
private UBLExtensionType[] uBLExtensionsField;
private NoteType[] noteField;
public UBLVersionIDType UBLVersionID
{
get
{
return this.uBLVersionIDField;
}
set
{
this.uBLVersionIDField = value;
}
}
public InvoiceTypeCodeType InvoiceTypeCode
{
get
{
return this.invoiceTypeCodeField;
}
set
{
this.invoiceTypeCodeField = value;
}
}
public UBLExtensionType[] UBLExtensions
{
get
{
return this.uBLExtensionsField;
}
set
{
this.uBLExtensionsField = value;
}
}
public NoteType[] Note
{
get
{
return this.noteField;
}
set
{
this.noteField = value;
}
}
}
public partial class NoteType : TextType1
{
}
public partial class TextType1 : TextType
{
}
public partial class TextType
{
private string languageIDField;
private string languageLocaleIDField;
private string valueField;
public string languageID
{
get
{
return this.languageIDField;
}
set
{
this.languageIDField = value;
}
}
public string languageLocaleID
{
get
{
return this.languageLocaleIDField;
}
set
{
this.languageLocaleIDField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}
public partial class UBLExtensionType
{
private IDType idField;
private NameType1 nameField;
private System.Xml.XmlElement extensionContentField;
public IDType ID
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
public NameType1 Name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
public System.Xml.XmlElement ExtensionContent
{
get
{
return this.extensionContentField;
}
set
{
this.extensionContentField = value;
}
}
}
The class "Invoice" has 4 fields to set data
private UBLVersionIDType uBLVersionIDField;
private InvoiceTypeCodeType invoiceTypeCodeField;
private UBLExtensionType[] uBLExtensionsField;
private NoteType[] noteField;
As you can see in the code, I set data to "uBLVersionID" and "InvoiceTypeCode", but I have not been able to assign data to notefield, and I don't know to set "uBLExtensionfield".
Does someone know how to do that?
Code below compiles with no errors. I added missing classes. The line with the ******* is causing issues.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
InvoiceType oInvoiceType = new InvoiceType(); // my main object
// using object UBLVersionIDType
UBLVersionIDType oUBLVersionIDType = new UBLVersionIDType();
IdentifierType oIdentifierType = new IdentifierType();
oIdentifierType.Value = "UBL 2.1";
//oUBLVersionIDType.schemeID = oIdentifierType.schemeID;
oUBLVersionIDType.Value = oIdentifierType.Value;
// using object InvoiceTypeCodeType
InvoiceTypeCodeType oInvoiceTypeCode = new InvoiceTypeCodeType();
CodeType oCodeType = new CodeType();
oCodeType.Value = "01";
oInvoiceTypeCode.Value = oCodeType.Value;
// using Note
NoteType oNoteType = new NoteType();
//oNoteType.Value = new ******************************************** bad
TextType oTextType = new TextType(); // this show error
oTextType.Value = "This is a Note 1"; // this show error
oNoteType.Value = oTextType.Value; // this show error
// asign main object
oInvoiceType.UBLVersionID = oUBLVersionIDType;
oInvoiceType.InvoiceTypeCode = oInvoiceTypeCode;
//oInvoiceType.Note = oNoteType; // this show error !!!!!!!!
}
}
public class CodeType
{
public string Value { get; set; }
}
public class IdentifierType
{
public string Value { get;set;}
}
public class UBLVersionIDType
{
public string Value { get; set; }
}
public class InvoiceTypeCodeType
{
public string Value { get; set; }
}
public partial class InvoiceType
{
private UBLVersionIDType uBLVersionIDField;
private InvoiceTypeCodeType invoiceTypeCodeField;
private UBLExtensionType[] uBLExtensionsField;
private NoteType[] noteField;
public UBLVersionIDType UBLVersionID
{
get
{
return this.uBLVersionIDField;
}
set
{
this.uBLVersionIDField = value;
}
}
public InvoiceTypeCodeType InvoiceTypeCode
{
get
{
return this.invoiceTypeCodeField;
}
set
{
this.invoiceTypeCodeField = value;
}
}
public UBLExtensionType[] UBLExtensions
{
get
{
return this.uBLExtensionsField;
}
set
{
this.uBLExtensionsField = value;
}
}
public NoteType[] Note
{
get
{
return this.noteField;
}
set
{
this.noteField = value;
}
}
}
public partial class NoteType : TextType1
{
}
public partial class TextType1 : TextType
{
}
public partial class TextType
{
private string languageIDField;
private string languageLocaleIDField;
private string valueField;
public string languageID
{
get
{
return this.languageIDField;
}
set
{
this.languageIDField = value;
}
}
public string languageLocaleID
{
get
{
return this.languageLocaleIDField;
}
set
{
this.languageLocaleIDField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}
public class IDType
{
}
public class NameType1
{
}
public partial class UBLExtensionType
{
private IDType idField;
private NameType1 nameField;
private System.Xml.XmlElement extensionContentField;
public IDType ID
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
public NameType1 Name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
public System.Xml.XmlElement ExtensionContent
{
get
{
return this.extensionContentField;
}
set
{
this.extensionContentField = value;
}
}
}
}
I solved myself, This is the REAL answer and its working fine
NoteType[] arrayNote = new NoteType[3];
NoteType oObj1 = new NoteType();
TextType oTextType = new TextType();
oTextType.Value = "This is Note 1";
oObj1.Value = oTextType.Value;
arrayNote[0] = oObj1;
oObj1.Value = "This is Note 2";
arrayNote[1] = oObj1;
Is there a way to map database fields to OOP complex type fields with Enterprise Library. I am calling stored procedures that retrieves all data that I would like to store into custom class.
Here I retrieve data from sp:
IEnumerable<WorkHistoryGrid> data = new List<WorkHistoryGrid>();
return db.ExecuteSprocAccessor<WorkHistoryGrid>("PensionPDF_RetrieveParticipantWorkHistoryForFund", pensionId, fund);
And here is my class
public class WorkHistoryGrid : BindableBase
{
private string _rateType;
private string _fundType;
private string _employer;
private string _employerName;
private string _local;
private string _dateBalanced;
private string _plan;
private string _fund;
private WorkHistoryGridMergeData _mergeData;
#region Properties
public WorkHistoryGridMergeData MergeData
{
get { return _mergeData; }
set { SetProperty(ref _mergeData, value); }
}
public string RateType
{
get { return _rateType; }
set { SetProperty(ref _rateType, value); }
}
public string FundType
{
get { return _fundType; }
set { SetProperty(ref _fundType, value); }
}
public string Employer
{
get { return _employer; }
set { SetProperty(ref _employer, value); }
}
public string EmployerName
{
get { return _employerName; }
set { SetProperty(ref _employerName, value); }
}
public string Local
{
get { return _local; }
set { SetProperty(ref _local, value); }
}
public string DateBalanced
{
get { return _dateBalanced; }
set { SetProperty(ref _dateBalanced, value); }
}
public string Plan
{
get { return _plan; }
set { SetProperty(ref _plan, value); }
}
public string Fund
{
get { return _fund; }
set { SetProperty(ref _fund, value); }
}
}
}
}
It works fine if I would create one class with all database fields, but I would like to have more control over it by mapping database fields to custom complex type properties.
Here is the answer in my case, in case someone would look for similar solution:
var workHistoryGridSetMapper = new WorkHistoryGridSetMapper();
db.ExecuteSprocAccessor<WorkHistoryGrid>("PensionPDF_RetrieveParticipantWorkHistory", workHistoryGridSetMapper, pensionId);
IResultSetMapper
public class WorkHistoryGridSetMapper : IResultSetMapper<WorkHistoryGrid>
{
public IEnumerable<WorkHistoryGrid> MapSet(IDataReader reader)
{
List<WorkHistoryGrid> workHistoryLst = new List<WorkHistoryGrid>();
using (reader) // Dispose the reader when we're done
{
while (reader.Read())
{
WorkHistoryGrid workHist = new WorkHistoryGrid();
workHist.Amount = reader.GetValue(reader.GetOrdinal("Amount")).ToString();
workHist.DateBalanced = reader.GetValue(reader.GetOrdinal("DateBalanced")).ToString();
workHist.Employer = reader.GetValue(reader.GetOrdinal("Employer")).ToString();
workHist.EmployerName = reader.GetValue(reader.GetOrdinal("EmployerName")).ToString();
workHist.Fund = reader.GetValue(reader.GetOrdinal("Fund")).ToString();
workHist.FundType = reader.GetValue(reader.GetOrdinal("FundType")).ToString();
workHist.Hours = reader.GetValue(reader.GetOrdinal("Hours")).ToString();
workHist.Local = reader.GetValue(reader.GetOrdinal("Local")).ToString();
workHist.Period = reader.GetValue(reader.GetOrdinal("Period")).ToString();
workHist.Plan = reader.GetValue(reader.GetOrdinal("Plan")).ToString();
workHist.RateAmount = reader.GetValue(reader.GetOrdinal("RateAmount")).ToString();
workHist.RateType = reader.GetValue(reader.GetOrdinal("RateType")).ToString();
workHist.Status = reader.GetValue(reader.GetOrdinal("Status")).ToString();
workHist.WorkMonth = reader.GetValue(reader.GetOrdinal("WorkMonth")).ToString();
workHist.MergeData = new WorkHistoryGridMergeData
{
MergeDateMerged = reader.GetValue(reader.GetOrdinal("MergeDateMerged")).ToString(),
MergeLastUpdated = reader.GetValue(reader.GetOrdinal("MergeLastUpdated")).ToString(),
MergeLastUpdatedUserId = reader.GetValue(reader.GetOrdinal("MergeLastUpdatedUserId")).ToString(),
MergeLastUpdatedUserType = reader.GetValue(reader.GetOrdinal("MergeLastUpdatedUserType")).ToString(),
MergeNewSsn = reader.GetValue(reader.GetOrdinal("MergeNewSsn")).ToString(),
MergeNotes = reader.GetValue(reader.GetOrdinal("MergeNotes")).ToString(),
MergeOldSsn = reader.GetValue(reader.GetOrdinal("MergeOldSsn")).ToString(),
MergeTrustId = reader.GetValue(reader.GetOrdinal("MergeTrustId")).ToString(),
MergeUserName = reader.GetValue(reader.GetOrdinal("MergeUserName")).ToString()
};
workHistoryLst.Add(workHist);
};
}
return workHistoryLst;
}
}
I want to serialize objects of class to xaml format. However, all of the properties name of class are directly serialized and I can't change their name.
I've used the
[DataMember(Name = "NameToChange")]`
attribute, but this still not solve the problem.
Please help me on this.
Here is the class:
public partial class XObject
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string AtName
{
get
{
return this.Name;
}
set
{
this.Name = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string AtType
{
get
{
return this.m_TypeToken;
}
set
{
this.m_TypeToken = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string AtSerialize
{
get
{
return this.m_SerializeToken;
}
set
{
this.m_SerializeToken = value;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<string> AtValue
{
get
{
return m_Values;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Dictionary<string, XObject> AtAttached
{
get
{
return m_AttachedAttributes;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string AtDynamic
{
get
{
return m_DynamicValue;
}
}
public void UpdateToken()
{
AtSerialize = (true == HasAttribute(AttributeNameToken_Serialize)) ? GetAttribute(AttributeNameToken_Serialize) : null;
AtType = (true == HasAttribute(AttributeNameToken_Type)) ? GetAttribute(AttributeNameToken_Type) : null;
foreach (XObject member in this)
{
member.UpdateToken();
}
}
private string m_TypeToken = null;
private string m_SerializeToken = null;
}
I have below class:
namespace ESF.Engine.SharedObjects.CatalogManagement
{
[DataContract()]
public class Customer
{
private string _LastName;
private System.DateTime _BirthDate;
private decimal _MoneyInCash;
private bool _IsActive;
private string _AdditionalInfo;
private decimal _ITEMID;
private string _NAME;
[DataMember()]
public string LastName
{
get
{
return this._LastName;
}
set
{
this._LastName = value;
}
}
[DataMember()]
public System.DateTime BirthDate
{
get
{
return this._BirthDate;
}
set
{
this._BirthDate = value;
}
}
[DataMember()]
public decimal MoneyInCash
{
get
{
return this._MoneyInCash;
}
set
{
this._MoneyInCash = value;
}
}
[DataMember()]
public bool IsActive
{
get
{
return this._IsActive;
}
set
{
this._IsActive = value;
}
}
[DataMember()]
public string AdditionalInfo
{
get
{
return this._AdditionalInfo;
}
set
{
this._AdditionalInfo = value;
}
}
[DataMember()]
public decimal ITEMID
{
get
{
return this._ITEMID;
}
set
{
this._ITEMID = value;
}
}
[DataMember()]
public string NAME
{
get
{
return this._NAME;
}
set
{
this._NAME = value;
}
}
}
}
After adding Service Reference, the proxy for this class generated under namespace which is default for client application.
Is it possible to force the class proxy to be generated as it is in server?
Thanks for your time.
I am trying to deserialize XML returned from an API call but am getting "InnerException:When converting a string to DateTime. parse the string to date the date before putting each variable into the DateTime object"
The XML looks like this
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<agentInventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:N1="demo.org.uk/demo/CustomsStatus" xmlns:N2="demo.org.uk/demo/UnLocation" xmlns:N3="demo.org.uk/demo/AirCarrier" xmlns="demo.org.uk/demo/AgentInventory">
<shed>ADX</shed>
<arrivalPort>
<N2:iataPortCode>LHR</N2:iataPortCode>
</arrivalPort>
<masterAirwayBillPrefix>125</masterAirwayBillPrefix>
<masterAirwayBillNumber>28121101</masterAirwayBillNumber>
<nominatedAgent>DRB</nominatedAgent>
<originPort>
<N2:iataPortCode>BOS</N2:iataPortCode>
</originPort>
<destinationPort>
<N2:iataPortCode>LHR</N2:iataPortCode>
</destinationPort>
<airCarrier>
<N3:carrierCode>BA</N3:carrierCode>
</airCarrier>
<flightNumber>235</flightNumber>
<flightDate>2012-02-09T00:00:00Z</flightDate>
<npx>10</npx>
<npr>0</npr>
<grossWeight>123.0</grossWeight>
<goodsDescription>BOOKS</goodsDescription>
<sdc>T</sdc>
<status1Set></status1Set>
<status2Set>false</status2Set>
<ccsCreationTime></ccsCreationTime>
<customsSummaryText />
<customsSummaryTime></customsSummaryTime>
<agentReference />
<isErtsPreArrival>false</isErtsPreArrival>
<isAgentPreArrival>false</isAgentPreArrival>
<isDeleted>false</isDeleted>
<finalised></finalised>
<createdOn>2012-01-24T11:50:40.86Z</createdOn>
<modifiedOn>2012-02-09T09:51:26.617Z</modifiedOn>
</agentInventory>
The code used to deserialize the XML is
if (storeXmlInventoryReturnData != null)
{
//DeSerialize XML from storeXmlInventoryReturnData variable
agentInventory myInventoryResponse = null;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(agentInventory));
myInventoryResponse = (
agentInventory)xmlSerializer.Deserialize(new StringReader(storeXmlInventoryReturnData)
);
Console.WriteLine(
#"\n\n\n INVENTORY RETURN DATA FOR AWB: {0}-{1} \n\n
Destination Port: {2} \n
Arrival Port: {3} \n
Carrier: {4} \n
Flight No: {5} \n
Flight Date: {6} \n
Customers Status: {7} \n
NPX: {8} \n
NPR {9} \n
SDC Code: {10}
\n\n Hit any key to exit...."
,
myInventoryResponse.masterAirwayBillPrefix,
myInventoryResponse.masterAirwayBillNumber,
myInventoryResponse.destinationPort,
myInventoryResponse.arrivalPort,
myInventoryResponse.airCarrier,
myInventoryResponse.flightNumber,
myInventoryResponse.flightDate,
myInventoryResponse.customsStatus,
myInventoryResponse.npx,
myInventoryResponse.npr,
myInventoryResponse.sdc,
myInventoryResponse.grossWeight,
myInventoryResponse.goodsDescription
);
Console.ReadLine();
}
else
{
Console.Write("No data returned");
}
}
The exception is thrown at;
myInventoryResponse = (
agentInventory)xmlSerializer.Deserialize(new StringReader(storeXmlInventoryReturnData));
I guess I need to convert the myInventoryResponse.flightDate to a DateTime object but I am at a loss how to achieve this?
namespace FreightSolutions {
using System;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Collections;
using System.Xml.Schema;
using System.ComponentModel;
using System.Collections.Generic;
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="asm.org.uk/Sequoia/AgentInventory")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="demo.org.uk/demo/AgentInventory", IsNullable=false)]
public partial class agentInventory {
private string shedField;
private unLocation arrivalPortField;
private string masterAirwayBillPrefixField;
private string masterAirwayBillNumberField;
private string houseAirwayBillNumberField;
private string splitReferenceNumberField;
private string nominatedAgentField;
private unLocation originPortField;
private unLocation destinationPortField;
private airCarrier airCarrierField;
private string flightNumberField;
private System.DateTime flightDateField;
private bool flightDateFieldSpecified;
private string npxField;
private string nprField;
private float grossWeightField;
private bool grossWeightFieldSpecified;
private string goodsDescriptionField;
private string sdcField;
private System.DateTime status1SetField;
private bool status1SetFieldSpecified;
private bool status2SetField;
private bool status2SetFieldSpecified;
private System.DateTime ccsCreationTimeField;
private bool ccsCreationTimeFieldSpecified;
private customsStatus customsStatusField;
private string customsSummaryTextField;
private System.DateTime customsSummaryTimeField;
private bool customsSummaryTimeFieldSpecified;
private string agentReferenceField;
private bool isErtsPreArrivalField;
private bool isErtsPreArrivalFieldSpecified;
private bool isAgentPreArrivalField;
private bool isAgentPreArrivalFieldSpecified;
private bool isDeletedField;
private bool isDeletedFieldSpecified;
private System.DateTime finalisedField;
private bool finalisedFieldSpecified;
private System.DateTime createdOnField;
private System.DateTime modifiedOnField;
private bool modifiedOnFieldSpecified;
public agentInventory() {
this.customsStatusField = new customsStatus();
this.airCarrierField = new airCarrier();
this.destinationPortField = new unLocation();
this.originPortField = new unLocation();
this.arrivalPortField = new unLocation();
}
public string shed {
get {
return this.shedField;
}
set {
this.shedField = value;
}
}
public unLocation arrivalPort {
get {
return this.arrivalPortField;
}
set {
this.arrivalPortField = value;
}
}
public string masterAirwayBillPrefix {
get {
return this.masterAirwayBillPrefixField;
}
set {
this.masterAirwayBillPrefixField = value;
}
}
public string masterAirwayBillNumber {
get {
return this.masterAirwayBillNumberField;
}
set {
this.masterAirwayBillNumberField = value;
}
}
public string houseAirwayBillNumber {
get {
return this.houseAirwayBillNumberField;
}
set {
this.houseAirwayBillNumberField = value;
}
}
public string splitReferenceNumber {
get {
return this.splitReferenceNumberField;
}
set {
this.splitReferenceNumberField = value;
}
}
public string nominatedAgent {
get {
return this.nominatedAgentField;
}
set {
this.nominatedAgentField = value;
}
}
public unLocation originPort {
get {
return this.originPortField;
}
set {
this.originPortField = value;
}
}
public unLocation destinationPort {
get {
return this.destinationPortField;
}
set {
this.destinationPortField = value;
}
}
public airCarrier airCarrier {
get {
return this.airCarrierField;
}
set {
this.airCarrierField = value;
}
}
public string flightNumber {
get {
return this.flightNumberField;
}
set {
this.flightNumberField = value;
}
}
public System.DateTime flightDate {
get {
return this.flightDateField;
}
set {
this.flightDateField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool flightDateSpecified {
get {
return this.flightDateFieldSpecified;
}
set {
this.flightDateFieldSpecified = value;
}
}
[System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
public string npx {
get {
return this.npxField;
}
set {
this.npxField = value;
}
}
[System.Xml.Serialization.XmlElementAttribute(DataType="integer")]
public string npr {
get {
return this.nprField;
}
set {
this.nprField = value;
}
}
public float grossWeight {
get {
return this.grossWeightField;
}
set {
this.grossWeightField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool grossWeightSpecified {
get {
return this.grossWeightFieldSpecified;
}
set {
this.grossWeightFieldSpecified = value;
}
}
public string goodsDescription {
get {
return this.goodsDescriptionField;
}
set {
this.goodsDescriptionField = value;
}
}
public string sdc {
get {
return this.sdcField;
}
set {
this.sdcField = value;
}
}
public System.DateTime status1Set {
get {
return this.status1SetField;
}
set {
this.status1SetField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool status1SetSpecified {
get {
return this.status1SetFieldSpecified;
}
set {
this.status1SetFieldSpecified = value;
}
}
public bool status2Set {
get {
return this.status2SetField;
}
set {
this.status2SetField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool status2SetSpecified {
get {
return this.status2SetFieldSpecified;
}
set {
this.status2SetFieldSpecified = value;
}
}
public System.DateTime ccsCreationTime {
get {
return this.ccsCreationTimeField;
}
set {
this.ccsCreationTimeField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool ccsCreationTimeSpecified {
get {
return this.ccsCreationTimeFieldSpecified;
}
set {
this.ccsCreationTimeFieldSpecified = value;
}
}
public customsStatus customsStatus {
get {
return this.customsStatusField;
}
set {
this.customsStatusField = value;
}
}
public string customsSummaryText {
get {
return this.customsSummaryTextField;
}
set {
this.customsSummaryTextField = value;
}
}
public System.DateTime customsSummaryTime {
get {
return this.customsSummaryTimeField;
}
set {
this.customsSummaryTimeField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool customsSummaryTimeSpecified {
get {
return this.customsSummaryTimeFieldSpecified;
}
set {
this.customsSummaryTimeFieldSpecified = value;
}
}
public string agentReference {
get {
return this.agentReferenceField;
}
set {
this.agentReferenceField = value;
}
}
public bool isErtsPreArrival {
get {
return this.isErtsPreArrivalField;
}
set {
this.isErtsPreArrivalField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool isErtsPreArrivalSpecified {
get {
return this.isErtsPreArrivalFieldSpecified;
}
set {
this.isErtsPreArrivalFieldSpecified = value;
}
}
public bool isAgentPreArrival {
get {
return this.isAgentPreArrivalField;
}
set {
this.isAgentPreArrivalField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool isAgentPreArrivalSpecified {
get {
return this.isAgentPreArrivalFieldSpecified;
}
set {
this.isAgentPreArrivalFieldSpecified = value;
}
}
public bool isDeleted {
get {
return this.isDeletedField;
}
set {
this.isDeletedField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool isDeletedSpecified {
get {
return this.isDeletedFieldSpecified;
}
set {
this.isDeletedFieldSpecified = value;
}
}
public System.DateTime finalised {
get {
return this.finalisedField;
}
set {
this.finalisedField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool finalisedSpecified {
get {
return this.finalisedFieldSpecified;
}
set {
this.finalisedFieldSpecified = value;
}
}
public System.DateTime createdOn {
get {
return this.createdOnField;
}
set {
this.createdOnField = value;
}
}
public System.DateTime modifiedOn {
get {
return this.modifiedOnField;
}
set {
this.modifiedOnField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool modifiedOnSpecified {
get {
return this.modifiedOnFieldSpecified;
}
set {
this.modifiedOnFieldSpecified = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="demo.org.uk/demo/UnLocation")]
public partial class unLocation {
private string itemField;
private ItemChoiceType itemElementNameField;
[System.Xml.Serialization.XmlElementAttribute("iataPortCode", typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("oceanPortCode", typeof(string))]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")]
public string Item {
get {
return this.itemField;
}
set {
this.itemField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemChoiceType ItemElementName {
get {
return this.itemElementNameField;
}
set {
this.itemElementNameField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="demo.org.uk/demo/UnLocation", IncludeInSchema=false)]
public enum ItemChoiceType {
/// <remarks/>
iataPortCode,
/// <remarks/>
oceanPortCode,
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="demo.org.uk/demo/CustomsStatus")]
public partial class customsStatus {
private string codeField;
private string statusTextField;
public string code {
get {
return this.codeField;
}
set {
this.codeField = value;
}
}
public string statusText {
get {
return this.statusTextField;
}
set {
this.statusTextField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="demo.org.uk/demo/AirCarrier")]
public partial class airCarrier {
private string carrierCodeField;
public string carrierCode {
get {
return this.carrierCodeField;
}
set {
this.carrierCodeField = value;
}
}
}
}
For my own sanity sake, I tried getting the provided XML to work with your classes and the nullable DateTime fields.
For them to work, replace the below properties with those linked below.
The default value for a DateTime object is DateTime.MinDate, so if the incoming value is null or empty, then the property will have a value of DateTime.MinDate anyway, for this you might need to additional validation/changes if your code needs to cater for this.
#region XML Nullable helper properties
[XmlElement(ElementName = "status1Set")]
public object status1SetXml
{
get
{
// Return the main property itself here and not the field to ensure that if there are changes made to the getter,
// the resulting XML will always have the right value
return status1Set;
}
set
{
// value passed in is of type XmlNode[], so convert and get the XmlNode text, which should be the DateTime we want
// !!ASSUMPTION!! That it will alwas be XmlNode[1] type
XmlNode[] inputValue = value as XmlNode[];
if (inputValue != null)
{
DateTime.TryParse(Convert.ToString(inputValue[0].InnerText), out status1SetField);
}
}
}
[XmlElement(ElementName="ccsCreationTime")]
public object ccsCreationTimeXml
{
get
{
// Return the main property itself here and not the field to ensure that if there are changes made to the getter,
// the resulting XML will always have the right value
return ccsCreationTime;
}
set
{
// value passed in is of type XmlNode[], so convert and get the XmlNode text, which should be the DateTime we want
// !!ASSUMPTION!! That it will alwas be XmlNode[1] type
XmlNode[] inputValue = value as XmlNode[];
if (inputValue != null)
{
DateTime.TryParse(Convert.ToString(inputValue[0].InnerText), out ccsCreationTimeField);
}
}
}
[XmlElement(ElementName = "customsSummaryTime")]
public object customsSummaryTimeXml
{
get
{
// Return the main property itself here and not the field to ensure that if there are changes made to the getter,
// the resulting XML will always have the right value
return customsSummaryTime;
}
set
{
// value passed in is of type XmlNode[], so convert and get the XmlNode text, which should be the DateTime we want
// !!ASSUMPTION!! That it will alwas be XmlNode[1] type
XmlNode[] inputValue = value as XmlNode[];
if (inputValue != null)
{
DateTime.TryParse(Convert.ToString(inputValue[0].InnerText), out customsSummaryTimeField);
}
}
}
[XmlElement(ElementName = "finalised")]
public object finalisedXml
{
get
{
// Return the main property itself here and not the field to ensure that if there are changes made to the getter,
// the resulting XML will always have the right value
return finalised;
}
set
{
// value passed in is of type XmlNode[], so convert and get the XmlNode text, which should be the DateTime we want
// !!ASSUMPTION!! That it will alwas be XmlNode[1] type
XmlNode[] inputValue = value as XmlNode[];
if (inputValue != null)
{
DateTime.TryParse(Convert.ToString(inputValue[0].InnerText), out finalisedField);
}
}
}
#endregion
#region Non XML properties
[XmlIgnore]
public System.DateTime status1Set
{
get { return this.status1SetField; }
set { this.status1SetField = value; }
}
[XmlIgnore]
public System.DateTime ccsCreationTime
{
get { return this.ccsCreationTimeField; }
set { this.ccsCreationTimeField = value; }
}
[XmlIgnore]
public System.DateTime customsSummaryTime
{
get { return this.customsSummaryTimeField; }
set { this.customsSummaryTimeField = value; }
}
[XmlIgnore]
public System.DateTime finalised
{
get { return this.finalisedField; }
set { this.finalisedField = value; }
}
#endregion