C# TypeInfo GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

Description

TypeInfo GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) Searches for the specified method whose parameters match the specified argument types and modifiers, using the specified binding constraints and the specified calling convention.

Syntax

TypeInfo.GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) has the following syntax.


public MethodInfo GetMethod(
  string name,/*from   w  ww.ja va2s.  c o m*/
  BindingFlags bindingAttr,
  Binder binder,
  CallingConventions callConvention,
  Type[] types,
  ParameterModifier[] modifiers
)

Parameters

TypeInfo.GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) 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.
  • binder - An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection.
  • binder - -or-
  • binder - A null reference (Nothing in Visual Basic), to use the DefaultBinder.
  • callConvention - The object that specifies the set of rules to use regarding the order and layout of arguments, how the return value is passed, what registers are used for arguments, and how the stack is cleaned up.
  • types - An array of Type objects representing the number, order, and type of the parameters for the method to get.
  • types - -or-
  • types - An empty array of Type objects (as provided by the EmptyTypes field) to get a method that takes no parameters.
  • modifiers - An array of ParameterModifier objects representing the attributes associated with the corresponding element in the types array. To be only used when calling through COM interop, and only parameters that are passed by reference are handled. The default binder does not process this parameter.

Returns

TypeInfo.GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) method returns An object representing the method that matches the specified requirements, if found; otherwise, null.

Example


using System;//  w  ww  .ja v a  2  s  . c  om
using System.Reflection;

class Program
{
    public void MethodA(int i, int j) { }

    public void MethodA(int[] i) { }

    public void MethodA(ref int r) {}

    public void MethodA(int i, out int o) { o = 100;}


  static void Main(string[] args)
  {
    MethodInfo mInfo;
    mInfo = typeof(Program).GetMethod("MethodA",
        BindingFlags.Public | BindingFlags.Instance,
        null,
        CallingConventions.Any,
        new Type[] { typeof(int), typeof(int) },
        null);
    Console.WriteLine("Found method: {0}", mInfo);
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo