So, I'm trying to XML serialize a List<IObject> torn from an interface, but IObjects are common types ... the best thing to use is code:
public interface IOSCMethod { string Name { get; } object Value { get; set; } Type Type { get; } } public class OSCMethod<T> : IOSCMethod { public string Name { get; set; } public T Value { get; set; } public Type Type { get { return _type; } } protected string _name; protected Type _type; public OSCMethod() { }
And I have a list of IOSCMethods:
List<IOSCMethod>
of which I add objects as follows:
List<IOSCMethod> methodList = new List<IOSCMethod>(); methodList.Add(new OSCMethod<float>() { Name = "/1/button1", Value = 0 }); methodList.Add(new OSCMethod<float[]>() { Name = "/1/array1", Value = new float[10] });
And this is the methodList that I am trying to serialize. But every time I try, I get "Can't serialize the interface", but when I create it (either IOSCMethod or OSCMethod<T> class), implement IXmlSerializable , I get the problem "cannot serialize an object with a constructor without parameters, but obviously I can't, because it's the interface! lame pants.
Any thoughts?
source share