protobuf-netclass-library

ProtoInclude on derived classes that inherit from class libraries


I have the following inheritance structure:

[ProtoContract]
public class User : UserCommon<User, Database.User>

[ProtoContract]
public abstract partial class UserCommon<T, T2> : DatabaseCachedObject<T, T2, int> where T : class

[ProtoContract]
public abstract class DatabaseCachedObject<T, T2, T3> where T : class

I understand for proper serialisation I need to declare ProtoInclude, I assume as follows:

[ProtoContract]
public class User : UserCommon<User, Database.User>

[ProtoContract]
[ProtoInclude(1, typeof(User))]
public abstract partial class UserCommon<T, T2> : DatabaseCachedObject<T, T2, int> where T : class

[ProtoContract]
[ProtoInclude(1, typeof(UserCommon))]
public abstract class DatabaseCachedObject<T, T2, T3> where T : class

The issue however, is the UserCommon and DatabaseCachedObject both exist in a class library and it is not possible to protoinclude the User type.

Is there any way around this, or do I painfully need to find another serialisation method?


Solution

  • Doh, after hours spent on this found the solution. In the application, I can add the following:

    RuntimeTypeModel.Default[typeof(UserCommon<C3.Code.Models.User, User>)].AddSubType(1000, typeof(Models.User));