我怎么知道vritual函数来自哪里? [英] How I know where a vritual function came from?

查看:82
本文介绍了我怎么知道vritual函数来自哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有以下问题:

如何获取在托管模块中首次声明虚函数的类型?

我需要知道类型,因为我想知道虚函数是在我的模块中还是在引用的模块中声明。

例如:以下类型在一个模块中,它引用外部程序集mscorlib
并声明虚函数DoSomething

类MyCollection:IEnumerable
{
public virtual void DoSomething(){...}
public IEnumerator GetEnumerator(){...}
} < br>
现在我想知道DoComething是第一次在MyCollection中声明,而GetEnumerator是在IEnumerable中声明的虚函数。

我尝试在模块的名称映射中使用scopelookup MyCollection的函数符号,但似乎导致死胡同,因为这两个函数都是虚函数,似乎很难理解为冷杉声明函数的位置时间。

谢谢。

Hi all,
I have the following question:

How can I get the type where a virtual function was declared for the first time in a managed module?

I need to know the type because I want to know if the virtual function was declared in my module or in a referenced one.

Ex: the following type is in a module that referene the external assembly mscorlib
and declare a virtual function DoSomething

class MyCollection : IEnumerable
{
    public virtual void DoSomething() { ... }
    public IEnumerator GetEnumerator() { ... }
}

Now I'd like to know that DoSomething was declared for the first time in MyCollection and GetEnumerator is a virtual function declared in IEnumerable.

I try to scopelookup in the name map of the module all the function symbols for MyCollection, but it seem to lead to a dead end because the two functions are both virtual and it seem difficult to understand where the fuctions are declared for the first time.

Thank you.

推荐答案

查看AggregateType.GetOverrideList(FunctionSymbol)。给定该类型的方法的类型和符号,它将提供BaseTypePath数据,向您显示重写类的方法。如果列表为空,则该类是引入该方法的类;如果没有,你可以看到基类和/或接口所在的位置。

Look at AggregateType.GetOverrideList(FunctionSymbol). Given a type and a symbol for a method on that type, it will provide BaseTypePath data showing you with methods in which classes are overriden. If the list is empty than this class is the one that has introduced the method; if not you can see where the base classes and/or interfaces lie.


这篇关于我怎么知道vritual函数来自哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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