CSharp examples for Reflection:Type
Metadata Viewer using reflection
using System;//from ww w .j a va 2 s . c om using System.Reflection; public class SimpleClass { public void Hello() { Console.WriteLine("Inside SimpleClass.Hello method"); } public void Goodbye() { Console.WriteLine("Inside SimpleClass.Goodbye method"); } } public class ClassExplorer { public static void Main() { Type ObjectType = typeof(SimpleClass); MethodInfo[] methods = ObjectType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); for (int i = 0; i <= methods.GetUpperBound(0); i++) { Console.WriteLine("{0} : {1}", i, methods[i]); } Console.Write("Enter method number to invoke: "); int idx = 6; Invoke(ObjectType, methods[idx]); } public static void Invoke(Type T, MethodInfo mi) { Object o = System.Activator.CreateInstance(T); object[] parameters = null; mi.Invoke(o, parameters); } }