12,162
社区成员
发帖
与我相关
我的任务
分享
//这里是gson API中的例子
class IdInstanceCreator implements InstanceCreator<Id> {
public Id createInstance(Type type) {
return new Id(Object.class, 0L);//我怎么知道是那个子类啊啊啊。。。
}
}
[Serializable]
public class Person
{
public string Name{get;set;}
//我其实是个IList
public object RelNames{get;set;}
}
实现
class Program
{
public static void Main(string[] args)
{
XmlSerializer sre = new XmlSerializer(typeof( Person),new Type[] {typeof(List<string>)});
FileStream fs = new FileStream("c:\\te.xml",FileMode.CreateNew,FileAccess.ReadWrite);
sre.Serialize( fs,new Peson{
Name = "andy",
RelNames = new List<string>{ "11111","22222"}
});
}
}