문제

In protobuf-net, which base class should be decorated? The class being directly subclassed or the furthest base class? Or both?

[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 { }
도움이 되었습니까?

해결책

The immediate parent of each expected sub-type, not the ancestor.

So: BaseClass needs to declare Intermediary, and Intermediary needs to declare 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 { }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top