How to get from ProtoBuf.Meta.MetaType
Type
it is mede from attributes ( ProtoIncludeAttribute
for example)?
for example we had created an assembly from:
[ProtoContract]
[ProtoInclude(TypeCode.MyClassChildCode, typeof(MyClassChild))]
public class MyClass {}
[ProtoContract]
public class MyClassChild: MyClass{}
We have got ProtoBuf.Meta.MetaType
for our MyClassChild
. And we want to get TypeCode.MyClassChildCode
from it. How to do such thing?
I'm not entirely sure that I understand the question, but it sounds like you are asking either:
MetaType
was made from attributes, vs by hand If that/those is/are the question(s), then: MetaType
does not explicitly track this. The information from the attributes is used to configure the MetaType
, and is then discarded. It is not uncommon, for example, to partially configure a type via attributes, and then apply some tweaks through code (for parts only known at runtime). All of the configuration is available on the MetaType
, though. You mention ProtoIncludeAttribute
, which is the sub-type data: once the MetaType
has been constructed, this is available via .GetSubtypes()
. Likewise there is .GetFields()
, and a range of properties for type-level configuration options ( UseConstructor
, etc).
There are some pieces which might be tricky to query at the moment - surrogates and factories leap to mind.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.