C# MethodInfo GetBaseDefinition
Description
MethodInfo GetBaseDefinition
When overridden in a derived
class, returns the MethodInfo object for the method on the direct or indirect
base class in which the method represented by this instance was first declared.
Syntax
MethodInfo.GetBaseDefinition
has the following syntax.
public abstract MethodInfo GetBaseDefinition()
Returns
MethodInfo.GetBaseDefinition
method returns A MethodInfo object for the first implementation of this method.
Example
This code example demonstrates the behavior of GetBaseDefinition.
/*w ww . j a va 2 s .com*/
using System;
using System.Reflection;
public class GetBaseDef {
public static void Main(String[] args){
Type t = typeof(B);
MethodInfo m;
m = t.GetMethod("B");
Console.WriteLine(m.GetBaseDefinition().DeclaringType + " " + m.GetBaseDefinition());
m = t.GetMethod("D", (BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.DeclaredOnly));
Console.WriteLine(m.GetBaseDefinition().DeclaringType + " " + m.GetBaseDefinition());
}
}
public class A
{
public virtual void B() { Console.WriteLine("C"); }
public virtual void C() { Console.WriteLine("C"); }
public virtual void D() { Console.WriteLine("E"); }
}
public class B : A
{
public override void C() { Console.WriteLine("C"); }
public new void D() { Console.WriteLine("D"); }
}
The code above generates the following result.