我有这样的界面
public interface IA{
IEnumerable<IB> Items {get;set;}
}
public interface IB{
int ID {get;set;}
}
如果我尝试序列化接口(interface),我会得到一个错误
Cannot serialize interface
如果我创建了界面的具体版本,则无法创建集合的具体版本。
public class classA:IA{
public IEnumerable<B> Items {get;set;} //this doesn't match the interface
}
但如果我执行以下操作,我们仍然会遇到序列化问题
public class classA:IA{
public IEnumerable<IB> Items {get;set;}
}
最佳答案
您确定要界面吗?泛型可能会帮助您序列化不同类型的 IEnumerable。
关于c# - 使用接口(interface)序列化子集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5639212/