开发者

serializable to derived classes

开发者 https://www.devze.com 2022-12-21 05:29 出处:网络
Is there an easy way to en开发者_如何学Goforce 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 ju

Is there an easy way to en开发者_如何学Goforce 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)?


  • We cannot use [Serializable] as gives error with an interface.
  • We may use [Serializable] attribute with base class but even then this attribute is not inherited. This does not seem possible.

Have a look a this link as well.

  • Enforcing serializable from an interface without forcing classes to custom serialize in C#.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号