WCF: DataMember attribute on property vs. member

后端 未结 7 2003
北海茫月
北海茫月 2021-01-30 20:27

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

private int m_SomeValue;

[DataMember]  
public int SomeVal         


        
7条回答
  •  一整个雨季
    2021-01-30 20:44

    As long as you use the Name marker, the contract is identical regardless of whether the field or property is used.

    [DataMember(Name="SomeValue")]
    private int m_SomeValue;
    

    However, there may be some permissions issues accessing private members, in particular on silverlight and CF - in which case I would recommend using the public property as the data-member. Actually, I would tend to always use a property unless I had a very good reason...

提交回复
热议问题