如何从TypeSpec获取TypeDef [英] How to get TypeDef from TypeSpec

查看:108
本文介绍了如何从TypeSpec获取TypeDef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过查看MDBG示例来实现托管调试器. 目前,我一直在尝试使用IMetaDataImport获取基类层次结构方法.

I'm trying to implement managed debugger looking at MDBG sample. Currently I'm stuck trying to get base class hierarchy methods using IMetaDataImport.

EnumMethods ,我是在使用时,枚举表示指定类型方法的MethodDef令牌.但我想列举类层次结构中的所有方法.为此,我使用的是GetTypeDefProps,它返回ptkExtends,它是表示基类的令牌.问题在于基类可以由TypeDef,TypeRef或TypeSpec表示.

EnumMethods, that I'm using, enumerates MethodDef tokens representing methods of the specified type. But I want to enumerate all the methods in class hierarchy. To do that I'm using GetTypeDefProps, that returns ptkExtends, which is token representing the base class. The problem is that base class could be represented by TypeDef, TypeRef or TypeSpec.

如何从相对的TypeSpec获取基类TypeDef?

How can I get base class TypeDef from relative TypeSpec?

我已经阅读了ECMA第II部分规范,但并没有太大帮助...

I've read ECMA part II specifications, but it didn't help me a lot...

这是我到目前为止所得到的:

Here is what I got so far:

      int size;                    
      TypeAttributes pdwTypeDefFlags;
      m_importer.GetTypeDefProps(m_typeToken,
                    null,
                    0,
                    out size,
                    out pdwTypeDefFlags,
                    out ptkExtends
                    );

      //ptkExtends is correct TypeSpec token
      IntPtr ppvSig;
      uint pcbSig;
      m_importer.GetTypeSpecFromToken(ptkExtends, out ppvSig, out pcbSig);
      //I'm getting the TypeSpec Blob signature in ppvSig, how to use it to get TypeDef?!

推荐答案

如前所述,TypeSpec格式在分区II的第23.2.14节中定义,其表达方式类似于EBNF,在第23.1.16节中定义了终端.

As stated previously, the TypeSpec format is defined in Partition II Section 23.2.14, its expressed with something resembling EBNF with the terminals defined in section 23.1.16.

TypeSpec可以表示一系列不同类型的类型,但是对基类有意义的唯一类型是GENERICINST(封闭的泛型类型).

A TypeSpec can represent a range of different kinds of types, but the only one that makes sense for a base class is GENERICINST (a closed generic type).

TypeSpecBlob ::= GENERICINST (CLASS | VALUETYPE) TypeDefOrRefEncoded GenArgCount Type Type*
             | ...

TypeDefOrRefEncoded在23.2.8节中定义,压缩整数在23.2节的开始处定义,而Type在23.2.12节中定义.

TypeDefOrRefEncoded is defined in section 23.2.8, compressed integers are defined at the start of section 23.2 and Type is defined in section 23.2.12.

Type ::= CLASS TypeDefOrRefEncoded
     | VALUETYPE TypeDefOrRefEncoded
     | ...

鉴于您上一个示例(15 12 3C 01 12 36)中的字节,我的餐巾纸的背面"划痕如下:

Given the bytes from your previous example (15 12 3C 01 12 36), my 'back of the napkin' scratching's come up with the following:

15 // GENERICINST
12 //   CLASS
3C //     TypeDefOrRefEncoded = 0200000F (The TypeDef of the open generic type.)
01 //   GenArgCount = 1
12 //   CLASS
36 //     TypeDefOrRefEncoded = 0100000D (The TypeRef of the single type argument.)

这篇关于如何从TypeSpec获取TypeDef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆