How do I ignore event subscribers when serializing an object?

前端 未结 1 922
心在旅途
心在旅途 2021-02-07 11:47

When the following class is serialized with a BinaryFormatter, any objects subscribing to the Roar event will also be serialized, since references to t

相关标签:
1条回答
  • 2021-02-07 12:08

    You have to include "field:" as part of the [NonSerialized] attribute on the event.

    i.e.:

    [field: NonSerialized]
    public event EventHandler Roar;
    
    0 讨论(0)
提交回复
热议问题