I’m going through a lot of code and marking classes which I now want to persist with the Serialization attribute. I haven’t written the binary serialization/deserization engine as yet so guess I will answer my own question once that’s complete! – but thought I’d try get an earlier response here if that’s OK. I’ve come across some code which contains a property such as:
public string Id
{
get;
set;
}
Does the “Id” get serialized? I understand that underneath the compiler auto creates a class member, but does this get serialized correctly (since all the data members of the class instance are written to storage)? It feels like it won’t since you can’t place the Serialized/NonSerialized attribute on properties.
Thanks in advance.
You can use the
[field:NonSerialized]attribute to mark the backing field of events as being non-serializable, however it seems this is not possible with auto-properties. With auto-properties the backing fields will be serialized and the only way to prevent that behaviour is to transform them into regular properties and annotate the explicit backing fields with[NonSerialized]as normal.