So i have been going through our code base and I have seen some our DTO's have a mix and match of [DataMember]
and [IgnoreDataMember]
attributes.
IN the past, we have been told that if we do not want something in the DTO serialised, simply do not add the [DataMember]
attribute. Then I saw the other attribute and did some digging and it seems that this explicitly states that the property will not be serialised.
Now my question is, which is better? Adding [IgnoreDataMember]
or not adding anything.
I have asked around and it seems that [IgnoreDataMember]
is from the days when everything was serialised and you had to dictate what should be ignored (I believe in .Net 2). Then they changed it to the reverse and you had to explicitly state what SHOULD be serialised. Now it seems that you can do both.