When implemented by a subclass, this method returns the MethodInfo object for the method on the direct or indirect super class in which the method represented by this instance was first declared.
This implementation merely throws an exception unless a subclass must override this implementation.
[Visual Basic] MustOverride Public Function GetBaseDefinition() As MethodInfo [C#] public abstract MethodInfo GetBaseDefinition(); [C++] public: virtual MethodInfo* GetBaseDefinition() = 0; [JScript] public abstract function GetBaseDefinition() : MethodInfo;
For example, the FileStream class has a method named Close. This method is first declared in the Stream class. FileStream inherits from BufferedStream which inherits from Stream. If GetBaseDefinition is invoked on the MethodInfo that represents the Close method of FileStream, the MethodInfo for the Close method on Stream will be returned.
Return the parents definition for a method in an inheritance chain. Normally returns the base implementation for a method.
To get the GetBaseDefinition method, first get the class Type. From the Type, get the MethodInfo. From the MethodInfo, get the GetBaseDefinition.
The following Managed C++ code sample demonstrates the functionality of GetBaseDefinition.
[C++] #import <mscorlib.dll> using namespace Reflection; void main () { Type *type = Type::GetType(L"System.IO.FileStream"); MethodInfo *method = type->GetMethod(L"Close"); MethodInfo *baseMethod = method->GetBaseDefinition(); Console::Write(L"The base definition of FileStream::Close is "); Console::WriteLine(L"{0}::{1}.", baseMethod->ReflectedType->Name, baseMethod->Name); /** * Output: * The base definition of FileStream::Close is Stream::Close. */ }
[C#]
class Mymethodinfo { public static int Main() { Console.WriteLine ("\nReflection.MethodInfo"); //Get the Type and MethodInfo Type MyType = Type.GetType("System.IO.FileStream"); MethodInfo Mymethodinfo = MyType.GetMethod("Close"); MethodInfo Mybasemethod = Mymethodinfo.GetBaseDefinition(); //Get and display the Mymethodinfo GetBaseDefinition Console.Write ("\nThe base definition of " + MyType.FullName + "." + Mymethodinfo.Name +" is a " + Mymethodinfo.GetBaseDefinition()); //Get and display the GetBaseDefinition Console.Write ("\nThe base definition of " + MyType.FullName + "." + Mymethodinfo.Name +" is " + Mybasemethod.ReflectedType + ":" + Mybasemethod.Name); return 0; } } Produces the following output Reflection.MethodInfo The base definition of System.IO.FileStream.Close is a Void Close () The base definition of System.IO.FileStream.Close is System.IO.Stream:Close
MethodInfo Class | MethodInfo Members | System.Reflection Namespace