Ok so the class I want to use is declared with:
public static class ObjectXMLSerializer<T> where T : class
I have many objects that I want to serialize, but I do not know their “class”
object myclass = new MyNamespace.MyClass() as object;
How do I do the following… ?
ObjectXMLSerializer< ? >.Save(myclass,"output.xml");
I can’t do this because the type that is expected, is “class”
ObjectXMLSerializer< myclass.GetType() >.Save(myclass,"output.xml");
And this just wouldnt work …
ObjectXMLSerializer< object >.Save(myclass,"output.xml");
Any thoughts would be appreciated!
Don’t use generics if XML serialization is all that you care about:
Alternatively, look at the
XmlSerializerclass, it might already cover your requirements:To deserialize, though, since you must know the compile-time type of the object that you want, you could use generics on the deserialization method: