在protobuf-net中,哪个基类应该装饰?该类是直接子类还是最远的基类?或两者兼而有之?
[ProtoContract]
[ProtoInclude(42, typeof(Derived))] // Here?
public abstract class BaseClass { }
[ProtoContract]
[ProtoInclude(42, typeof(Derived))] // Or Here?
public abstract class Intermediary : BaseClass { }
[ProtoContract]
public class Derived : Intermediary { }
答案 0 :(得分:1)
每个预期子类型的直接父类,而不是祖先。
所以:BaseClass
需要声明Intermediary
,而Intermediary
需要声明Derived
:
[ProtoContract]
[ProtoInclude(42, typeof(Intermediary))]
public abstract class BaseClass { }
[ProtoContract]
[ProtoInclude(42, typeof(Derived))]
public abstract class Intermediary : BaseClass { }
[ProtoContract]
public class Derived : Intermediary { }