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

后端 未结 5 1144
梦毁少年i
梦毁少年i 2021-02-19 23:00

I have an interface that defines some methods I would like certain classes to implement.

public interface IMyInterface
{
    MethodA;
    MethodB;
}

Additi

5条回答
  •  误落风尘
    2021-02-19 23:42

    There does not seem to be a way to do this, but I wish there were.

    Note two things though:

    • The Serializable attribute can not be inherited from a base class, even if the base class is marked as abstract.

    • You don't technically need the Serializable attribute, IF you are using an XmlSerializer because it does not make use of object graphs.

提交回复
热议问题