WCF: DataMember attribute on property vs. member

后端 未结 7 2000
北海茫月
北海茫月 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:42

    In theory, and as long as you keep m_SomeValue always equal to SomeValue (like a simple getter/setter), nothing. Other than the name of the variable exposed by the WCF. (Obviously, if you tag the m_ variable, then your proxy class will also have the same m_ name. The proxy class will generate a public property whether you use a public/protected/internal/private field or property.

    However, if you have any special logic in your accessors that may modify the value returned (ToUpper()ing a string, for example), then you would return a different value.

提交回复
热议问题