Does the mono implementation of System.Xml.Serialization.XmlSerializer allow methods or properties to use interfaces? An interface and an abstract class should work exchangeable but the Microsoft runtime does not allow interfaces even when using the XmlElement(Type = typeof(someType)) attribute on that property.
Sample code:
public interface ISample { string val { get; } }
public abstract class ASample : ISample
{
public abstract string val { get; set; }
}
public class S : ASample
{
string v;
public S() : this("") {}
public S(string s) { v = s; }
public override string val { get { return v; } set { v = value; } }
}
public class Sample
{
string a, b;
[XmlElement(typeof(S))]
public ASample A { get { return new S(a); } set { a = value.val; } }
[/*XmlIgnore(),*/XmlElement(typeof(S))]
public ISample B { get { return new S(b); } set { b = value.val; } }
public Sample() { a = "a value"; b = "b value"; }
}
public class XmlSerialization
{
static public string ToString(object o)
{
System.IO.StringWriter w = new System.IO.StringWriter();
try
{
XmlSerializer serializer = new XmlSerializer(typeof(Sample));
serializer.Serialize(w,new Sample());
}
catch (System.Exception e)
{
System.Exception ie = e.InnerException;
while (ie != null)
{
System.Diagnostics.Debug.WriteLine(ie.ToString());
ie = ie.InnerException;
}
}
w.Close();
return w.ToString();
}
}
If I put comment out XmlIgnore I get the following output:
<?xml version="1.0" encoding="utf-16"?>
<Sample xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<A>
<val>a value</val>
</A>
</Sample>
