简体   繁体   English

当我不向[DataContract]中的字段添加[DataMember]时会发生什么?

[英]What happens when I don't add [DataMember] to a field in [DataContract]?

I am specifically interested in knowing that whether that particular field is serialised or not. 我特别想知道该特定字段是否已序列化。

For example, I have: 例如,我有:

[DataContract]
public class Node {
   [DataMember]
   public string Name;

   [DataMember]
   public int ID;
}

I am only interested in serialising the name, do I still need to decorate with ID with DataMember attribute? 我只想对名称进行序列化,是否还需要使用带有DataMember属性的ID进行修饰?

If you omit the attribute the value will not be serialized. 如果省略该属性,则该值将不会序列化。

So if you only need the name, you don't need to decorate the ID 因此,如果只需要名称,则不需要装饰ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM