Reputation: 3995
I know you can serialize private fields with DataContractSerializer, but I just want to save a minimum amount of data that is easily human editable. After DataContractSerializer has done its thing is there a function that I can override or set in the DataContractSerializer class that just sets up the private fields after it has done the de-serialization?
[DataContract()]
[KnownType(typeof(stateCom))]
[KnownType(typeof(stateIp))]
abstract public class state
{
[DataMember()]
public string tag;
[DataMember()]
public byte Id;
public HandleConnection master;
// default data contstructor for xml serialization
public state()
{
}
public abstract void openPort();
public abstract void closePort();
}
Upvotes: 0
Views: 396
Reputation: 32343
You could create e.g. OnDeserialized
method in your class and apply OnDeserializedAttribute
to it like:
[DataContract()]
[KnownType(typeof(stateCom))]
[KnownType(typeof(stateIp))]
abstract public class state
{
[DataMember()]
public string tag;
[DataMember()]
public byte Id;
public HandleConnection master;
// default data contstructor for xml serialization
public state()
{
}
public abstract void openPort();
public abstract void closePort();
[OnDeserialized]
internal void OnDeserialized(StreamingContext context)
{
// this is called after deserialization
}
}
Upvotes: 2