我需要避免序列化Event类成员,因为当事件由未标记为Serializable的对象处理时,序列化将失败.
我尝试在Event类成员上使用NonSerialized属性,但无法编译.这行代码:
<NonSerialized()> Public Event PropertyValueChanged()
Run Code Online (Sandbox Code Playgroud)
产生以下错误:
属性'NonSerializedAttribute'不能应用于'PropertyValueChanged',因为该属性在此声明类型上无效.
Public Event PropertyValueChanged() ' compiles but needs the extra handling described below
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以避免序列化活动成员?
如果事件未被处理,这不是问题,我可以通过在序列化之前克隆对象(并忽略事件)来解决它.只是想知道是否有更好的方法.
谢谢.