Is there a way to specify how a field/property of Type object is formatted
when serializing to xml for specific types? For example, I have a class with
an object property which can a number of value types, including a DateTime
or a reference to a class. If it is a date I want to format it as xsd:date
rather than xsd:dateTime. If I do this
[XmlInclude(typeof(MyClass2)]
public MyClass{
[XmlElement("Value", typeof(object), IsNullable=true)]
[XmlElement(typeof(DateTime), DataType="date")]
public object Value;
}
DateTime values are serialized properly, but the name of the element is
changed to 'date'. You cannot specify an XmlElement attrtibute with the same
Name property more than once.
Thanks.