|
Hi,
I have a xml document, provided from an external partner, which has a bit of a crazy heirachy. I have a simplified example of it here:
<?xml version="1.0" encoding="utf-8"?>
<Engine>
<Cylinder>
<Volume>0</Volume>
</Cylinder>
<Battery>
<Capacity>0</Capacity>
</Battery>
</Engine>
And here is the equivalent code, a want to be able to serialize and deserialize to and from:
public class Engine
{
public Engine()
{
EngineParts = new List<EnginePart>();
}
[YAXCollection(YAXCollectionSerializationTypes.RecursiveWithNoContainingElement)]
public List<EnginePart> EngineParts { get; set; }
}
public abstract class EnginePart
{
[YAXAttributeForClass]
public string Id { get; set; }
}
public class Cylinder : EnginePart
{
public int Volume { get; set; }
}
public class Battery : EnginePart
{
public int Capacity { get; set; }
}
As you can see both Cylinder and Battery inherits from EnginePart. There can be a lot of different EngineParts, and also multiple of the same type added at the same time.
My problem is that YAX expects and realtype attribute, in order to identify a concret EnginePart class, e.g.:
<?xml version="1.0" encoding="utf-8"?>
<Engine xmlns:yaxlib="http://www.sinairv.com/yaxlib/">
<EnginePart Id="" yaxlib:realtype="Playground.Cylinder">
<Volume>0</Volume>
</EnginePart>
<EnginePart Id="" yaxlib:realtype="Playground.Battery">
<Capacity>0</Capacity>
</EnginePart>
</Engine>
Is there a way to tell the YAXSerializer to use the class name of the derived type, so when it sees an element with the name <Cylinder> it knows it should use the type Playground.Cylinder?
Kind regards,
Lars
ps. thanks for making a serializer which is easy to use and customize
|