471,605 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

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

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
Dec 21 '05 #1
2 1593
What about Type.IsSerializable?

Dan

"TimJR" wrote:
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

Dec 21 '05 #2
No, Type.IsSerializable is for Binary serialization, not Xml Serialization so
it does not identify if an object (or type) is xml serializable.

"Dan Kelley" wrote:
What about Type.IsSerializable?

Dan


Dec 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Bijay Kumar | last post: by
4 posts views Thread by Heinz | last post: by
reply views Thread by Bijay Kumar | last post: by
5 posts views Thread by Mark Rae | last post: by
3 posts views Thread by Jason | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.