I am generating classes from XSD
and need to populate the classes to serialize to xml.
I have different classes, containing all the info that goes into the classes generated.
The problem is that the generated classes come in versions, and properties in those classes are other classes in the same version.
class LocalData
{
public MyClass property { get; set; }
}
class XmlVersion1
{
public MyClassV1 property { get; set; }
}
class XmlVersion2
{
public MyClassV2 property { get; set; }
public MyClassXV2 newProperty { get; set; }
}
The data in MyClassV1
and V2
are basically the same, so the same code can be used.
I wanted to make a factory that just took the LocalData
class and any of the versioned classes and populated the data in the versioned class, but I run into a problem when I want to do property = new MyClassVx
, because the factory does not know which version it's supposed to create.
I could do
if (parameter is MyClassV1)
paramter.MyClassV1 = new MyClassV1
and so on, but that is a LOT of code.
This is for generating xml messages that are specified by an external company, and they come in different versions, and we have to be able to serialize and deserialize the content into our internal system.