Chris Riley

Chris Riley

  • NA
  • 85
  • 0

How to provide class to from object ?

Sep 16 2010 6:45 AM

Hi,

I am using an XML serializer found on code project, to serialize an object I must provide its type ie;
ObjectXMLSerializer<MyNamespace.MyClass>.Save(new MyNamespace.MyClass(),"filename.xml");

I am experimenting with this and would like to know if it is possible to provide the "class" for the object, if you look at the code below you will see I am passing the class objects type which is invalid, is there anyway I can pass the class here without knowing what class the object is?

if only there were obj.GetClass() ......

public
static bool Serialize2File(object obj, string filename)
{
try
{
ObjectXMLSerializer< obj.GetType() >.Save(obj, filename);
}
catch(Exception ex)
{
return false;
}
return true;
}

Thanks!

Answers (1)