dynamic invocation is demonstrated with MethodInfo.Invoke and Type.InvokeMember
using System;
using System.Reflection;
class Starter {
static void Main() {
MyClass obj = new MyClass();
Type tObj = obj.GetType();
MethodInfo method = tObj.GetMethod("MethodA");
method.Invoke(obj, null);
tObj.InvokeMember("MethodA", BindingFlags.InvokeMethod,
null, obj, null);
}
}
class MyClass {
public void MethodA() {
Console.WriteLine("MyClass.Method invoked");
}
}
Related examples in the same category