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?
Related question
Is it possible to tell if a .NET virtual method has been overriden in a derived class?
Check its DeclaringType property.
DeclaringType
if (methodInfo.DeclaringType == typeof(Foo)) { // ... }
1.4m articles
1.4m replys
5 comments
57.0k users