Using JSON.net, how do I prevent serializing properties of a derived class, when used in a base class context?

后端 未结 6 1601
花落未央
花落未央 2020-12-01 00:20

Given a data model:

[DataContract]
public class Parent
{
    [DataMember]
    public IEnumerable Children { get; set; }
}

[DataContract]
publ         


        
6条回答
  •  甜味超标
    2020-12-01 00:44

    I have not used JSON.Net in particular so not positive this will help you. If JSON.Net derives itself from the .Net serialization system then you should be able to add the [NonSerialized] attribute to your properties you do now wish to be serialized in the base class. When you call the serialize methods on the base class, serialization should then skip those elements.

提交回复
热议问题