我有一个问题一直困扰着我 - 我在我的类中定义了自定义子集合,当对象被实例化时会被实例化。在反序列化期间是否可以告诉 json.net 不要实例化新集合,而只是将反序列化的集合项添加到现有集合中?我正在谈论的代码类似于下面,您可以看到我将一个函数传递给它用于构建和编译表达式的集合的构造函数,我真的不想弄清楚如何获得该创建序列化程序中发生的逻辑。谢谢!
public class ClassWithChildCollection
{
private CustomCollection<TestClass1> _childCollection;
public CustomCollection<TestClass1> ChildCollection
{
get
{
return _childCollection;
}
}
public ClassWithChildCollection()
{
_childCollection= new CustomCollection<TestClass1>(this, x => x.TestClass1Property);
}
}