C# TypeInfo GetMethod(String, Type[])

Description

TypeInfo GetMethod(String, Type[]) Searches for the specified public method whose parameters match the specified argument types.

Syntax

TypeInfo.GetMethod(String, Type[]) has the following syntax.


public MethodInfo GetMethod(
  string name,
  Type[] types
)

Parameters

TypeInfo.GetMethod(String, Type[]) has the following parameters.

  • name - The string containing the name of the public method to get.
  • 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.

Returns

TypeInfo.GetMethod(String, Type[]) method returns An object representing the public method whose parameters match the specified argument types, if found; otherwise, null.

Example


using System;// w ww  . j  av a 2 s .com
using System.Reflection;

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

    public void MethodA(int[] i) { }

    public unsafe 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",
        new Type[] { typeof(int).MakePointerType() });
    Console.WriteLine("Found method: {0}", mInfo);

    // Get MethodA(ref int r)
    mInfo = typeof(Program).GetMethod("MethodA",
        new Type[] { typeof(int).MakeByRefType() });
    Console.WriteLine("Found method: {0}", mInfo);

    // Get MethodA(int i, out int o)
    mInfo = typeof(Program).GetMethod("MethodA",
        new Type[] { typeof(int), typeof(int).MakeByRefType() });
    Console.WriteLine("Found method: {0}", mInfo);

  }
}




















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo