[Serializable]
class DOThis
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Value
{
get
{
if (_name == "Hi")
return "Hey Hi";
else
return "Sorry I dont know you";
}
}
}
I have the above class to be serialized using BinaryFormatter. Below is the serialization code,
DOThis obj = new DOThis();
obj.Name = "Ho";
BinaryFormatter bfm = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bfm.Serialize(ms, obj);
Here how to ignore the property 'Value' from being serialized and also in deserialize, as I can always retrieve 'Value' property using 'Name' property?
You don't have to make any changes to your code:
BinaryFormatter
only serializes fields, not properties, so it won't serializeValue
.Here's a hex dump of the resulting
MemoryStream
which shows that only "_name" and "Ho" are serialized: