C# protobuf从子级到父级的净继承

C# protobuf从子级到父级的净继承,c#,inheritance,protocol-buffers,protobuf-net,C#,Inheritance,Protocol Buffers,Protobuf Net,我有一个家长班,我想有很多扁平的孩子。这意味着一个类将固有10个或更多不同的类 这是我的 基类: [ProtoContract] [ProtoInclude(500, typeof(Message1Send))] [ProtoInclude(501, typeof(Message2Send))] public class MessageBase { [ProtoMember(1)] public string Topic {get;set;} [ProtoMember(2

我有一个家长班,我想有很多扁平的孩子。这意味着一个类将固有10个或更多不同的类

这是我的

基类:

[ProtoContract]
[ProtoInclude(500, typeof(Message1Send))]
[ProtoInclude(501, typeof(Message2Send))]
public class MessageBase
{
    [ProtoMember(1)]
    public string Topic {get;set;}
    [ProtoMember(2)]
    public string Action { get; set; }       
}
许多儿童班中的2个:

[ProtoContract]    
public class Message1Send : MessageBase
{        
    [ProtoMember(1)]
    public string Property1 { get; set; }
}

[ProtoContract]    
public class Message2Send : MessageBase
{        
    [ProtoMember(1)]
    public string Property1 { get; set; }
}
我希望能够告诉子对象我是基类的一部分

我不知道该怎么做,我的基类如下所示:

[ProtoContract]
[ProtoInclude(500, typeof(Message1Send))]
[ProtoInclude(501, typeof(Message2Send))]
[ProtoInclude(502, typeof(Message3Send))]
[ProtoInclude(503, typeof(Message4Send))]
[ProtoInclude(504, typeof(Message5Send))]
[ProtoInclude(505, typeof(Message6Send))]
[ProtoInclude(506, typeof(Message7Send))]
[ProtoInclude(507, typeof(Message8Send))]
[ProtoInclude(508, typeof(Message9Send))]
[ProtoInclude(509, typeof(Message10Send))]
public class MessageBase
{
    [ProtoMember(1)]
    public string Topic {get;set;}
    [ProtoMember(2)]
    public string Action { get; set; }       
}

有没有一种方法可以让每个Send类只向基类添加一个引用,这样我就不必为我创建的每个平面子类添加ProtoInclude?

问题在于可靠性。反射提供了很多可重复/可靠的保证,非常重要的是,如果您现在序列化数据,然后编辑应用程序以添加两种新类型,每种类型的编号仍然与最初相同。即使您添加了一些新类型,重命名了一些类型,并且可能删除了两个您没有真正使用的类型

该属性通过使字段编号可重复来保证这一点。它位于父级(而不是子级)上的原因是,向上遍历类型链比向下遍历更可靠

但是:如果您有一种可靠的、可重复的方法来为子类型生成字段号,那么可以使用
RuntimeTypeModel
根据自己的喜好配置序列化程序