Click here to Skip to main content
15,886,091 members
Articles / Programming Languages / XML
Alternative
Tip/Trick

Get rid of XmlInclude when using XmlSerializer

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
17 Nov 2011CPOL 5.1K  
The above solution made me grin as it helped me solved my serialization puzzle. However, if you have an extensible format with components spread over multiple assemblies, this solution may not pick up all the types.I brute force it as follows:List knownTypes = new...

The above solution made me grin as it helped me solved my serialization puzzle. However, if you have an extensible format with components spread over multiple assemblies, this solution may not pick up all the types.


I brute force it as follows:


C#
List<type> knownTypes = new List<type>();

foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
    knownTypes.AddRange(Assembly.GetExecutingAssembly().GetTypes().Where(
    t => typeof(XMLBinaryPackageInfo).IsAssignableFrom(t)));
}

My rationale is that this code is unlikely to be called often enough to worry about enumerating such a potentially vast number of types. I don't cache this stuff but you can keep track of assembly loading / unloading if you must. Mileage may vary!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --