I have a XSD2Code generated Class and all is working. However I want to generate and store IDs as GUIDs on all Complex class types ie Order, OrderItem etc. to facilitate CRUD from the object Hierarchy. So instead of adding an ID element to every "Record" style dataset in the XML Schema I have created a parent abstract Class from which my XSD2Code classes inherits from. My code can see the ID, and it generates the ID, however it seems that XSD2Code does not see ID and thus ID does not get Serialized.
My Parent Class code:
namespace OrderSystem
{
public abstract class Master
{
private string IdField;
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 999)]
public String ID
{
get
{
if (IdField == null)
{
IdField = Guid.NewGuid().ToString();
}
return IdField;
}
}
}
}
Which is used by my XSD generated code:
public partial class Product : Master
{
My instinct is that ID is not being serialized, because it is not in the generated class ie "Product" which is a little odd since the rest of the code can see it because it is inherited.
Any thoughts please?
EDIT:
public class Master
{
private string IdField;
[System.Xml.Serialization.XmlAttributeAttribute()]
public String ID
{
get
{
//if (IdField == null)
//{
// IdField = Guid.NewGuid().ToString();
//}
return IdField;
}
set
{
if (value == null)
{
IdField = Guid.NewGuid().ToString();
}
else
{
IdField = value;
}
}
}
}