Why have private fields in data contracts modified through public ones?
Posted
by
Nordvind
on Stack Overflow
See other posts from Stack Overflow
or by Nordvind
Published on 2012-06-21T21:12:27Z
Indexed on
2012/06/21
21:15 UTC
Read the original article
Hit count: 178
When you make a new WCF project, sample service is generated for you. The default data contract is (I've just changed the string type field title):
[DataContract] public class CompositeType { bool boolValue = true; string name = "";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string Name
{
get { return name; }
set { name = value; }
}
}
What is the point of having those private fields boolValue and name? Is it a good practice writing some data sanitizing or some other manipulations in contract, thus bloating it? It seems the only sane reason for me not writing to fields directly. So is it a bloatware or it has some reason behind it?
© Stack Overflow or respective owner