C# 如何从ProtoBuf.Meta.MetaType类型中获取它是从属性中获取的?

C# 如何从ProtoBuf.Meta.MetaType类型中获取它是从属性中获取的?,c#,protocol-buffers,protobuf-net,C#,Protocol Buffers,Protobuf Net,如何从ProtoBuf.Meta.MetaTypeType中获取它是从属性中获取的(例如ProtoIncludeAttribute) 例如,我们从以下内容创建了一个程序集: [ProtoContract] [ProtoInclude(TypeCode.MyClassChildCode, typeof(MyClassChild))] public class MyClass {} [ProtoContract] public class MyClassChild: MyClass{} 我们已经

如何从
ProtoBuf.Meta.MetaType
Type
中获取它是从属性中获取的(例如
ProtoIncludeAttribute

例如,我们从以下内容创建了一个程序集:

[ProtoContract]
[ProtoInclude(TypeCode.MyClassChildCode, typeof(MyClassChild))]
public class MyClass {}

[ProtoContract]
public class MyClassChild: MyClass{}
我们已经为我们的
MyClassChild
获得了
ProtoBuf.Meta.MetaType
。我们想从中获取
TypeCode.MyClassChildCode
。如何做这样的事情?

我不完全确定我是否理解这个问题,但听起来你在问:

  • 我能告诉你一个
    元类型是由属性还是手工制作的吗
  • 或者:我可以得到实际使用的属性吗
如果这是问题,那么:
MetaType
不会明确跟踪这一点。属性中的信息用于配置
元类型
,然后被丢弃。例如,通过属性部分配置类型,然后通过代码应用一些调整(对于仅在运行时已知的部分),这种情况并不少见。不过,所有配置都可以在
元类型上找到。您提到了
ProtoIncludeAttribute
,它是子类型数据:一旦构建了
元类型,就可以通过
.getsubtype()
获得它。同样,还有
.GetFields()
,以及一系列类型级配置选项的属性(
UseConstructor
,等等)


现在有一些问题可能很难查询——代理和工厂跃入脑海。

似乎
ProtoBuf.Meta.MetaType
ProtoIncludeAttribute
属性中清除了它的
ProtoBuf.Meta.MetaType.Type
,您能澄清/重新表述这个问题吗?我不明白你想问什么。我几乎可以肯定地回答这个问题,但我需要先理解这个问题。