I have a base class (eg)
[XmlType("address")]
[XmlInclude(typeof(AddressUK))]
[XmlInclude(typeof(AddressEurope))]
public class AddressBase
{
// No serialized properties
}
and as you can see, I've decorated it to serialize to an element of 'address' and to expect some subclasses:
public class AddressUK : AddressBase
{
[XmlElement("company")]
[AddressField(AddressFieldType.Organisation, Required = true, MaxSize = 60)]
public string Company { get; set; }
}
public class AddressEurope : AddressBase
{
[XmlElement("company")]
[AddressField(AddressFieldType.Organisation, Required = true, MaxSize = 40)]
public string Company { get; set; }
}
The only reason I have these subclasses is so that I can decorate them with custom AddressField
attributes. (Each subclass potentially has different settings, and the base class has methods that populates the address fields based on these attributes). Other than the AddressField attributes, these sub classes should serialize identically
But when I do serialize this my address node serializes as (eg)
... <address p5:type="AddressUK" xmlns:p5="http://www.w3.org/2001/XMLSchema-instance"> <company>Company Name</company> ...
I'd really like it to just serialize as <address>
without the type and namespace information. I suspect it's trying to help me there, as without that information I wouldn't be able to deserialize it correctly, but for my scenario (integration with 3rd party provider) that information is redundant and not expected by them (and I don't need to deserialize in such an awkward way)
Is this possible, or am I approaching this from entirely the wrong angle?