I have a class that I am serializing. I put [XmlIgnore] on the properties I
don't want to serialize.
I want to deserialize it to itself like this:
XmlSerializer deserializer = new XmlSerializer(typeof(MyClass));
StringReader strReader = new StringReader(xmlData);
XmlReader xmlReader = new XmlTextReader(strReader);
this = (MyClass)deserializer.Deserialize(xmlReader);
However, you can't assign to "this". It's read only. I know that, so now
I'm creating a new instance of the class, and then copying all properties of
that instance to my actual instance like this:
XmlSerializer deserializer = new XmlSerializer(typeof(MyClass));
StringReader strReader = new StringReader(xmlData);
XmlReader xmlReader = new XmlTextReader(strReader);
MyClass myClass = new MyClass();
myClass = (MyClass)deserializer.Deserialize(xmlReader);
moduleID = myClass.moduleID;
boID = myClass.boID;
parentModuleID = myClass.parentModuleID;
parentBoID = myClass.parentBoID;
AND NOW THE QUESTION...
Is there a way I could iterate through the public properties of the class to
automatically copy all properties of that instance to my actual instance?
Maybe using Reflection?
I want to make it so that if I add more public properties they will
automatically be deserialized so that I don't have to specify for them to be
copied to my actual instance.
Thanks,
John