Get method by parameters types and modifiers, using the specified binding constraints in CSharp

Description

The following code shows how to get method by parameters types and modifiers, using the specified binding constraints.

Example


using System;/* w  w  w .  j  a  v  a2s .  c  o m*/
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",
        BindingFlags.Public | BindingFlags.Instance,
        null,
        new Type[] { typeof(int), typeof(int) },
        null);
    Console.WriteLine("Found method: {0}", mInfo);
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type