Why is using [DataMember(EmitDefaultValue = false)] not recommended?

后端 未结 1 1104
我在风中等你
我在风中等你 2020-12-30 20:13

In WCF you can define a contract using the [DataContract] and [DataMember] attributes, like this:

[DataContract]
public class Sampl         


        
相关标签:
1条回答
  • 2020-12-30 21:02

    The reason is at the bottom of the article that you link to. The short version is:

    • When the EmitDefaultValue is set to false, it is represented in the schema as an annotation specific to Windows Communication Foundation (WCF). There is no interoperable way to represent this information. In particular, the "default" attribute in the schema is not used for this purpose, the minOccurs attribute is affected only by the IsRequired setting, and the nillable attribute is affected only by the type of the data member.

    • The actual default value to use is not present in the schema. It is up to the receiving endpoint to appropriately interpret a missing element.

    0 讨论(0)
提交回复
热议问题