I have two classes: GameObject
and SampleObject : GameObject
and a list of type GameObject
. I've serialized instances of these classes into a XML document. My problem occurs once I deserialize (load) this document.
In XML file instances are serialized as:
<Root>
<GameObject>
<Type>Namespace.MyType</Type>
</GameObject>
</Root>
Where Type represents desired type. And each instance is serialized under GameObject tag.
After parsing this document I obtain a list of GameObject
. Now I need to restore correct type:
foreach (GameObject g in myList)
{
GameObject tempObject = (GameObject)Activator.CreateInstance(Type.GetType(g.TypeString));
}
Problem is that tempObject
is blank (which is correct). I'd like to (with some shorthand) restore common (shared) variables between g
and tempObject
. Ex:
tempObject.Property1 = g.Property1
tempObject.Property2 = g.Property2
Aucun commentaire:
Enregistrer un commentaire