ShouldSerialize pattern and DataContractSerializer

后端 未结 2 494
余生分开走
余生分开走 2020-12-10 19:31

Is there a way to get the ShouldSerialize* pattern working with DataContractSerializer?

Here is a small example:

I have a simple cl

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 19:44

    You should set the IsRequired attribute on the DataMember:

    [DataContract]
    public class Person
    {
      [DataMember(IsRequired = False, EmitDefaultValue = False)]
      public string FirstName { get; set; }
      ...
    }
    

提交回复
热议问题