I have a class which is serialized to XML. This class has an Object member variable. How can I properly serialize this item? Obviously, it should be written as a string, but when read, it should become any type.
public class MyClass
{
public MyClass()
: this("", null)
{
}
public MyClass(String name, Object value)
{
Name = name;
Value = value;
}
[XmlAttribute("name")]
public String Name;
[XmlAttribute("value")] // Won't work!
public Object Value;
}
Edit: Interestingly, [XmlElement()] is able to serialize the Object type. Thus, one workaround is to use a value instead of an attribute.