سؤال

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