如何确定所述的MethodInfo是基本方法的重写 [英] How to determine if the MethodInfo is an override of the base method

查看:183
本文介绍了如何确定所述的MethodInfo是基本方法的重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,以确定是否是我从一个类型实例的GetMethod的电话得到的MethodInfo对象由类型实现的,或它的基础。

例如:

 富富=新的Foo();
。MethodInfo的MethodInfo的= foo.GetType()GetMethod的(的ToString的BindingFlags |实例);
 

ToString方法可在Foo类或未实现。我想知道,如果我得到了富执行?

  

相关问题

     

<一个href="http://stackoverflow.com/questions/839984/is-it-possible-to-tell-if-a-net-virtual-method-has-been-overriden-in-a-derived-c">Is可以说,如果一个.NET虚方法已经被重写在派生类中?

解决方案

检查其 DeclaringType 属性。

 如果(methodInfo.DeclaringType == typeof运算(富)){
   // ...
}
 

I'm trying to determine if the MethodInfo object that I get from a GetMethod call on a type instance is implemented by the type or by it's base.

For example:

Foo foo = new Foo();
MethodInfo methodInfo = foo.GetType().GetMethod("ToString",BindingFlags|Instance);

the ToString method may be implemented in the Foo class or not. I want to know if I'm getting the foo implementation?

Related question

Is it possible to tell if a .NET virtual method has been overriden in a derived class?

解决方案

Check its DeclaringType property.

if (methodInfo.DeclaringType == typeof(Foo)) {
   // ...
}

这篇关于如何确定所述的MethodInfo是基本方法的重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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