C# Type GetMethod(String, BindingFlags)
Description
Type GetMethod(String, BindingFlags)
searches for
the specified method, using the specified binding constraints.
Syntax
Type.GetMethod(String, BindingFlags)
has the following syntax.
public MethodInfo GetMethod(
string name,
BindingFlags bindingAttr
)
Parameters
Type.GetMethod(String, BindingFlags)
has the following parameters.
name
- The string containing the name of the method to get.bindingAttr
- A bitmask comprised of one or more BindingFlags that specify how the search is conducted.bindingAttr
- -or-bindingAttr
- Zero, to return null.
Returns
Type.GetMethod(String, BindingFlags)
method returns An object representing the method that matches the specified requirements,
if found; otherwise, null.
Example
The following example gets the method that matches the specified binding flags.
// www . jav a2 s. com
using System;
using System.Reflection;
class Program
{
public void MethodA() { }
static void Main(string[] args)
{
// Get MethodA()
MethodInfo mInfo = typeof(Program).GetMethod("MethodA",
BindingFlags.Public | BindingFlags.Instance);
Console.WriteLine("Found method: {0}", mInfo);
}
}
The code above generates the following result.