可序列化为派生类
有没有一种简单的方法来强制派生类必须可序列化?
假设我定义了一个需要派生类可序列化的接口。根据 这篇文章,我不能只在接口中指定可序列化属性,因为派生类不需要尊重这一点。
我相信我可以让该接口继承自 ISerialized 接口,但这是否意味着派生类无法使用该属性来指定序列化(而不是实际实现 ISerialized 的方法)?
Is there an easy way to enforce a derived class must be serialiable?
Suppose I define a interface that needs the derived classes to be serializable. According to this post, I cannot just specify the serializable attribute in the interface, because derived classes don't need to respect that.
I believe I could have the interface inherit from the ISerializable interface, but does that mean that the derived class couldn't use the attribute to specify serialization (as opposed to actually implementing the methods for ISerializable)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[Serialized]
作为给出接口错误。
[Serialized]
属性与
base
类,但即便如此属性不被继承。这确实
似乎不可能。
也看看这个链接。
接口而不强制类
在 C# 中自定义序列化。
[Serializable]
asgives error with an interface.
[Serializable]
attributewith
base
class but even then thisattribute is not inherited. This does
not seem possible.
Have a look a this link as well.
interface without forcing classes to
custom serialize in C#.