próbuję uruchomić kod podobny do tego:Serializacja interfejsy
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
namespace ConsoleApplication1
{
[Serializable]
[XmlInclude(typeof(List<Class2>))]
public class Class1
{
private IList<Class2> myArray;
public IList<Class2> MyArray
{
get { return myArray; }
set { myArray = value; }
}
}
public class Class2
{
private int myVar;
public int MyProperty
{
get { return myVar; }
set { myVar = value; }
}
}
class Program
{
static void Main(string[] args)
{
XmlSerializer ser = new XmlSerializer(typeof(Class1), new Type[] { typeof(List<Class2>) });
FileStream stream = File.OpenWrite("Data.xml");
ser.Serialize(stream, new List<Class1>());
stream.Close();
}
}
}
Czy ktoś mógłby mi wyjaśnić, co robię źle?
dostaję:
Nie można szeregować członek .. MyArray ... bo to jest interfejs.
Czy XmlInclude nie powinien tego rozwiązać?
Ktokolwiek powiedział coś o deserializacji ...? –