List Methods : Method « Reflection « C# / CSharp Tutorial






using System;
using System.Reflection;

public interface IFaceOne
{
  void MethodA();
}

public interface IFaceTwo
{
  void MethodB();
}

public class MyClass: IFaceOne, IFaceTwo
{
  public enum MyNestedEnum{}
  
  public int myIntField;
  public string myStringField;

  public void myMethod(int p1, string p2)
  {
  }

  public int MyProp
  {
    get { return myIntField; }
    set { myIntField = value; }
  }

  void IFaceOne.MethodA(){}
  void IFaceTwo.MethodB(){}
}

public class MainClass
{
  public static void Main(string[] args)
  {
    MyClass f = new MyClass();

    Type t = f.GetType();
    MethodInfo[] mi = t.GetMethods();
    foreach(MethodInfo m in mi)
      Console.WriteLine("Method: {0}", m.Name);
    
  }
}
Method: myMethod
Method: get_MyProp
Method: set_MyProp
Method: GetType
Method: ToString
Method: Equals
Method: GetHashCode








19.5.Method
19.5.1.Deeper Reflection: iterate through the methods of the class
19.5.2.Deeper Reflection: Invoking Functions
19.5.3.Invoke methods using reflection
19.5.4.List Methods
19.5.5.Obtain the metadata tokens
19.5.6.Inspecting a method's body
19.5.7.Dynamically Invoking A Method
19.5.8.Finding Particular Members
19.5.9.Call string method with reflection and Expression
19.5.10.Invoke member method with created instance from reflection
19.5.11.Use reflection to invoke methods
19.5.12.Use DefinePInvokeMethod method to create a PInvoke method.
19.5.13.Get the method that matches the specified binding flags.