I'm working with .NET XmlSerializer. In order to properly serialize multiple classes that inherit from another one I must include the name along with the type of the subclass everywhere a use them. In my case I have a group of classes that represent expressions. But is a lot of code replicated everywhere. Is there a way to go from this:
public class ClassThatHasExpression
{
[XmlElement("equal", typeof(Equals)),
XmlElement("equals", typeof(Equals))]
[XmlElement("notequal", typeof(NotEquals)),
XmlElement("notequals", typeof(NotEquals)),
XmlElement("diff", typeof(NotEquals))]
[XmlElement("multiequals", typeof(MultiEquals))]
[XmlElement("in", typeof(In))]
[XmlElement("isnull", typeof(IsNull))]
[XmlElement("notnull", typeof(NotNull))]
[XmlElement("true", typeof(True))]
[XmlElement("false", typeof(False))]
[XmlElement("neg", typeof(Not)),
XmlElement("not", typeof(Not))]
[XmlElement("equiv", typeof(Equiv))]
[XmlElement("inequiv", typeof(InEquiv)),
XmlElement("xor", typeof(InEquiv))]
[XmlElement("and", typeof(And))]
[XmlElement("or", typeof(Or))]
[XmlElement("imp", typeof(Implication))]
public object expression { get; set; }
}
To something like this:
public class ClassThatHasExpression
{
[IsExpression]
public object expression { get; set; }
}
Or this:
public class ClassThatHasExpression
{
public Expression expression { get; set; }
}