Type.GetMethod Method
Gets a specific method of the current Type.
Overload List
Searches for the public method with the specified name.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function GetMethod(String) As MethodInfo
[C#] public MethodInfo GetMethod(string);
[C++] public: MethodInfo* GetMethod(String*);
[JScript] public function GetMethod(String) : MethodInfo;
Searches for the specified method, using the specified binding constraints.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Overridable Function GetMethod(String, BindingFlags) As MethodInfo Implements IReflect.GetMethod
[C#] public virtual MethodInfo GetMethod(string, BindingFlags);
[C++] public: virtual MethodInfo* GetMethod(String*, BindingFlags);
[JScript] public function GetMethod(String, BindingFlags) : MethodInfo;
Searches for the specified public method whose parameters match the specified argument types.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function GetMethod(String, Type()) As MethodInfo
[C#] public MethodInfo GetMethod(string, Type[]);
[C++] public: MethodInfo* GetMethod(String*, Type[]);
[JScript] public function GetMethod(String, Type[]) : MethodInfo;
Searches for the specified public method whose parameters match the specified argument types and modifiers.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function GetMethod(String, Type(), ParameterModifier()) As MethodInfo
[C#] public MethodInfo GetMethod(string, Type[], ParameterModifier[]);
[C++] public: MethodInfo* GetMethod(String*, Type[], ParameterModifier[]);
[JScript] public function GetMethod(String, Type[], ParameterModifier[]) : MethodInfo;
Searches for the specified method whose parameters match the specified argument types and modifiers, using the specified binding constraints.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Overridable Function GetMethod(String, BindingFlags, Binder, Type(), ParameterModifier()) As MethodInfo Implements IReflect.GetMethod
[C#] public virtual MethodInfo GetMethod(string, BindingFlags, Binder, Type[], ParameterModifier[]);
[C++] public: virtual MethodInfo* GetMethod(String*, BindingFlags, Binder*, Type[], ParameterModifier[]);
[JScript] public function GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[]) : MethodInfo;
Searches for the specified method whose parameters match the specified argument types and modifiers, using the specified binding constraints and the specified calling convention.
Supported by the .NET Compact Framework.
[Visual Basic] Overloads Public Function GetMethod(String, BindingFlags, Binder, CallingConventions, Type(), ParameterModifier()) As MethodInfo
[C#] public MethodInfo GetMethod(string, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]);
[C++] public: MethodInfo* GetMethod(String*, BindingFlags, Binder*, CallingConventions, Type[], ParameterModifier[]);
[JScript] public function GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) : MethodInfo;
Example
[Visual Basic, C#, C++] The following example displays information about a method named MyFunc in the class MyClass.
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of GetMethod. For other examples that might be available, see the individual overload topics.
[Visual Basic] Imports System Imports System.Reflection Imports Microsoft.VisualBasic Public Class [MyClass] Public i As Integer = 10 Public j As Integer = 2 Public Function MyFunc(ByVal i As Integer, ByVal j As Integer) As Integer Dim k As Integer k = i * 10 - j Return k End Function 'MyFunc End Class '[MyClass] Public Class Type_GetMethod Public Shared Sub Main() Try ' Get the type of MyClass. Dim myType As Type = GetType([MyClass]) ' Get information for MyFunc(int, int). Dim myMemberInfo As MemberInfo = myType.GetMethod("MyFunc", BindingFlags.Public Or BindingFlags.Instance, Nothing, CallingConventions.Any, New Type() {GetType(Integer), GetType(Integer)}, Nothing) Console.WriteLine(ControlChars.NewLine + "Displaying method MyFunc: " + ControlChars.NewLine) ' Display the method information. Console.WriteLine("{0}", myMemberInfo) Catch e As Exception Console.WriteLine("Exception : {0}", e.Message.ToString()) End Try End Sub 'Main ' End Class 'Type_GetMethod [C#] using System; using System.Reflection; public class MyClass { public int i = 10; public int j = 2; public int MyFunc(int i , int j) { int k; k = i * 10 - j; return k; } } public class Type_GetMethod { public static void Main() { try { // Get the type of MyClass. Type myType = typeof(MyClass); // Get the method information for MyFunc(int, int). MemberInfo myMemberInfo = myType.GetMethod("MyFunc", BindingFlags.Public | BindingFlags.Instance, null, CallingConventions.Any, new Type[] {typeof(int),typeof(int)}, null); Console.WriteLine("\nDisplaying information for MyFunc: \n"); // Display the method information. Console.WriteLine("{0}", myMemberInfo); } catch(Exception e) { Console.WriteLine("Exception : {0}", e.Message); } } } [C++] #using <mscorlib.dll> using namespace System; using namespace System::Reflection; public __gc class MyClass { public: int i; int j; int MyFunc(int i , int j) { int k; k = i * 10 - j; return k; } }; int main() { try { // Get the type of MyClass. Type* myType = __typeof(MyClass); // Get the method information for MyFunc(int, int). Type* temp0 [] = {__typeof(int), __typeof(int)}; MemberInfo* myMemberInfo = myType->GetMethod(S"MyFunc", static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance), 0, CallingConventions::Any, temp0, 0); Console::WriteLine(S"\nDisplaying information for MyFunc: \n"); // Display the method information. Console::WriteLine(S"{0}", myMemberInfo); } catch (Exception* e) { Console::WriteLine(S"Exception : {0}", e->Message); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.