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

后端 未结 5 1143
梦毁少年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

    If you want to use the default serialization then you need to add the SerializableAttribute . One alternative would be to use an abstract class instead of an interface, then add the SerializableAttribute to the abstract class. If you're implementing your own custom serialization then you want to implement ISerializable, otherwise stick with SerializableAttribute .

提交回复
热议问题