Get serializable types

23 views Asked by At

I have a huge amount of classes with serialization-attributes as follows:

[XmlRoot(...)]
public MyClass { }

or also

[XmlType(...)]
public MyClass { }

Or whatever exists. How do I get all those types that have xml-serializer-information? I tried by checking if the types implement IXmlSerializable but that gives me only a few as most of the classes have only these attributes set whilst not implementing the interface explicitly.

Is there any way to get all those types that have such an attribute?

EDIT: I know that I can get the classes that have a special attribute by using GetCustomAttributes on the type. This seems to be inconvenient to me because I have to know all these attributes (XmlRoot, XmlType, XmlInclude, any missing that are applayable to classes?). Furthermore such a query would be quite ugly:

if (type.GetCustomAttribute(typeof(XmlRoot)).Length > 0 || 
    type.GetCustomAttribute(typeof(XmlType)).Length > 0 ||
    type.GetCustomAttribute(typeof(XmlRoot)).Length > 0)

Having said this I hoped for another solution.

0

There are 0 answers