I am currently using BinaryFormatter for creating a stream. I am aware of the fact that I can mark a property with the attribute [field: NonSerialized] if I want it to be ignored by the BinaryFormatter during serialization. My question is if there is a way for me to specify that all null properties of a field should be ignored during Binary Serialization ? I am currently doing something like this to get the stream
var formatter = new BinaryFormatter();
using (var stream = new MemoryStream())
{
formatter.Serialize(stream, MyObjectinstance);
}
What is your particular use case of excluding that from the serialization? Null won't take up hardly any space, and this won't improve deserialization or serialization performance. When deserializing you could also handle null differently as well, by having the OnDeserialized event handled.