I have a base class like the following:
[Serializable]
public class SerializableDomainObject<T>
{
public SerializableDomainObject()
{
ID = Guid.NewGuid();
}
[DataMember(Name="ID", Order = 0)]
public Guid ID { get; private set; }
public void Save()
{
// serialize
}
public void Load()
{
// deserialize
}
}
I then have lots of derived classes from this, here is an example of one:
[DataContract(Name="MyDomainObject")]
public class MyDomainObject : SerializableDomainObject<MyDomainObject>
{
public MyDomainObject()
{
}
public MyDomainObject(string name)
{
Name = name;
}
[DataMember(Order = 1)]
public string Name { get; private set; }
}
Once serialized here is the output:
<MyDomainObject xmlns="http://schemas.datacontract.org/2004/07/DomainObjects" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<_x003C_ID_x003E_k__BackingField>2b3c00f6-1b15-4a6b-bd6c-a1f447ea5a34</_x003C_ID_x003E_k__BackingField>
<Name>AName</Name>
</MyDomainObject>
Why is the ID property not being serialized with the name I have provided in the DataMember attribute in the base class?