I have some simple POCO object:
public class ProductCategoryDTO
{
public string Name { get; set; }
public DateTime ModifiedDate { get; set; }
}
As sometimes field order is important (for example, if sending to Infopath forms), I need to keep element order when serializing.
And now I am confused, what attributes I should use for the class and for each field. I know that:
- DataContractSerializer uses [DataContract] and [DataMember(Order = n)]
- XMLSerializer uses [Serializable] and [XmlElementAttribute(Order = n)].
Then what attributes to use if I want to support both XMLSerializer and DataContractSerializer, so it can used in both WCF or ASP. web services?
I don’t see any reason why you couldn’t put both attributes on the class and member properties, if you really must. Doesn’t look nice, but if it works for you, that’s just fine!