How can i see if an object is Xml Serializable at runtime?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am looking for a way to determine in RunTime if a given object is Xml
Serializable (short of trying to serialize it to xml and catching the
exception).

Is this possible?

Since an object must have a Default Constructor to be XmlSerializable I have
tried something like:

Type valueType = aRandomObject.GetType();
bool isXmlSerializable = valueType.IsClass && !valueType.IsValueType
? valueType.GetConstructor(new Type[]{}) != null : true;

but this is not correct. Am I on the right track or missing something
obvious...?

Any ideas?

Thanks in advance
Tim
 
No, Type.IsSerializable is for Binary serialization, not Xml Serialization so
it does not identify if an object (or type) is xml serializable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top