It may occasionally be useful to serialize an object that exposes event without serializing all subscribers to the object's events. Unfortunately,
[NonSerialized]
public event EventHandler<EventArgs> PropertyChanged;
results in an error because NonSerializedAttribute only applies to fields. What to do?
There's a poorly documented, hackish feature that lets us work through this
[field: NonSerialized]
public event EventHandler<EventArgs> PropertyChanged;
The field prefix indicates that the attribute should apply only to the backing field.
Warning!
As far as I can tell, this is not an officially supported feature! If it is, I can't find it in the docs. This workaround should not be used in production code! Production code may benefit from the use of the "Memento" pattern, or something similar, to capture only the desired state.
... Umm... it's documented in the code right above.