相关疑难解决方法(0)

如何忽略二进制序列化的Event类成员?

我需要避免序列化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)

有没有其他方法可以避免序列化活动成员?

如果事件未被处理,这不是问题,我可以通过在序列化之前克隆对象(并忽略事件)来解决它.只是想知道是否有更好的方法.

谢谢.

.net c# vb.net events binary-serialization

16
推荐指数
2
解决办法
7025
查看次数

标签 统计

.net ×1

binary-serialization ×1

c# ×1

events ×1

vb.net ×1