If I am serializing and later deserializing a class using DataContractSerializer
how can I control the initial values of properties that were not serialized?
Actually the correct way of doing it is by using the OnDeserializing attribute (notice the "ing" suffix). The method marked with this attribute is called before the member values are deserialized.
You can use a serialization callback. Add the following method to your Person class:
[OnDeserialized]
void OnDeserialized(StreamingContext context)
{
this.IsNew = true;
}
Another option is to remove the [DataContract] and [DataMember] attributes. In this case DCSerializer will call your constructor when it deserializes.