I have the following hierarchy -
ProtoBase
SomeType :ProtoBase
TypeCacheData<T> : ProtoBase
ListCacheData<T> : TypedCacheData<List<T>>
and am using a
ListCacheData<SomeType>
in the code -
I wasn't sure what inheritance attributes should be included at the latest release to accomplish this -
TypeCacheData has a property called Value of, which is of type T.
I've tried a few things but got the "ProtoBase" can only participate in one inheritance hierarchy..
What's the uptodate recommended way to accomplish this ?
I saw this - ProtoBuf-Net ProtoInclude Generic Type Subclass
but it's pretty old...
Thanks !
UPDATE - I eventually came up with the following - which seems to work -
Does it follow the lines of the recommended way to go , or is my solution overly complex or perhaps even wrong ?
Thanks !!
[ProtoContract]
[ProtoInclude(2, typeof(LiteAnswer))]
[ProtoInclude(5, typeof(TypeCacheData<List<int>>))]
[ProtoInclude(6, typeof(TypeCacheData<List<short>>))]
[ProtoInclude(7, typeof(TypeCacheData<List<LiteAnswer>>))]
public class ProtoBase
{
}
[ProtoContract]
[ProtoInclude(100, typeof(ListCacheData<LiteAnswer>))]
[ProtoInclude(101, typeof(ListCacheData<int>))]
[ProtoInclude(102, typeof(ListCacheData<short>))]
public class TypeCacheData<T> : ProtoBase {
// omitting class implementation to keep example concise
}
[ProtoContract]
public class ListCacheData<T> : TypeCacheData<List<T>>
When using the above I'm able to deserialize/ deserialize properly isntances of the following -
ListCacheData<int>
ListCacheData<short>
ListCacheData<LiteAnswer>