Can I control serialization of certain fields using XmlSerializer in c#? Fox example an property named “Type”(string) to be serialized as something else instead of string.
Thanks in advance.
Can I control serialization of certain fields using XmlSerializer in c#? Fox example an
Share
You can control a few things via
XmlElement/XmlAttributeannotations — the name of the element, whether it is an attribute or full XML element, etc. However, you can’t change the type directly. If you need to support any type of complex serialization scheme,XmlSerializeris not a good choice due to its many limitations. You’re better off usingDataContractSerializer(see “Using Data Contracts” in the WCF documentation) or maybe even writing it yourself.If you just want to change the XML type of the resulting serialized data (e.g. using a custom XML type or namespace), you can do that with the
XmlTypeattribute, but that will only work for types you have declared and not primitive CLR types (e.g. you can’t make a string into an integer or another more complex type).