| Start |
|---|
Formatting: Custom DateTime format |
Serialize object |
Deserialize object |
Behaviour: Map array name to property (XmlArray) |
Behaviour: Map Element name to Property |
Efficiently building multiple serializers with derived types specified dynamically Where we came fromSometimes we can't provide all of the required metadata needed for the XmlSerializer framework in attribute. Suppose we have a base class of serialized objects, and some of the derived classes are unknown to the base class. We can't place an attribute for all of the classes which are not know at the design time of the base type. We could have another team developing some of the derived classes. What can we doWe can use In this example, the the Base type is not aware of it's derived types, which is normal in OOP. Doing it efficientlyLuckily, there is a method which addresses this particular problem - supplying known types for multiple serializers efficiently: System.Xml.Serialization.XmlSerializer.FromTypes Method (Type[]) (opens new window) The FromTypes method allows you to efficiently create an array of XmlSerializer objects for processing an array of Type objects. Here is a complete code sample: Output: What's in the outputThis error message recommends what we tried to avoid (or what we can not do in some scenarios) - referencing derived types from base class:
This is how we get our derived class in the XML:
Here is a working example fiddle (opens new window) RemarksDo not use the |
Read Article
https://develop.horje.com/learn/1434/reference