WCF:物业与成员的DataMember属性 [英] WCF: DataMember attribute on property vs. member

查看:176
本文介绍了WCF:物业与成员的DataMember属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WCF,什么是应用数据成员属性在属性之间的区别

In wcf, what is the difference between applying the DataMember attribute on a property

private int m_SomeValue;

[DataMember]  
public int SomeValue {
  get {...}
  set {...}
}

而不是一个成员变量

instead of a member variable

[DataMember]  
private int m_SomeValue;

public int SomeValue {
  get {...}
  set {...}
}

推荐答案

在一般情况下,你应该赞成申请将DataMember属性的财产,而不是在私人领域。该属性应用到外地,而不是唯一的原因是,如果该属性是只读的(即它有没有setter)。

In general, you should favor applying the DataMember attribute on the property, rather than on the private field. The only reason to apply the attribute to the field instead is if the property were read-only (i.e. it has no setter).

这篇关于WCF:物业与成员的DataMember属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆