/// <summary>
/// Test to see if the type can be XML serialized
/// </summary>
/// <param name="objectToTest"></param>
/// <returns></returns>
private static bool CanBeXmlSerialized(Type objectToTest)
{
Type[] interfaces = objectToTest.GetInterfaces();
bool containsIXmlSerializable = interfaces.Contains(typeof(IXmlSerializable));
return containsIXmlSerializable || objectToTest.IsSerializable;
}
Refactorings
No refactoring yet !
Elij
November 20, 2008, November 20, 2008 01:55, permalink
If you have an instance at run time you could do the following
private static bool canBeXmlSerialized(object @object)
{
return @object is IXmlSerializable || @object.GetType().IsSerializable;
}
sbehnke.myopenid.com
November 20, 2008, November 20, 2008 16:22, permalink
That's an interesting use of @. Since Visual Studio 7 and C# 1.0 I've not thought to call anything @object.
I need a fast method to check to see if a type is XML Serializable, be that with the [Serializable] attribute or the IXmlSerializable interface. This is what I came up with. Can we make it better?