Reflection and Delegates
-
Is it possible given two strings (class name and method name) to dynamically create an instance of the class and get a delegate pointing to the method? For example (almostcode):
public delegate void ActionHandler(Message m); string className = "Exony.Runtime.StateServices.Test.States.Stopped"; string actionName = "OnStart"; Type t = Type.GetType(className); object instance = t.Assembly.CreateInstance(t.FullName); ActionHandler handler = ?CREATE_DELEGATE?(instance, actionName); // Add the handler to an event map. fsm.Handlers += handler;
Thanks in advance, James. -
Is it possible given two strings (class name and method name) to dynamically create an instance of the class and get a delegate pointing to the method? For example (almostcode):
public delegate void ActionHandler(Message m); string className = "Exony.Runtime.StateServices.Test.States.Stopped"; string actionName = "OnStart"; Type t = Type.GetType(className); object instance = t.Assembly.CreateInstance(t.FullName); ActionHandler handler = ?CREATE_DELEGATE?(instance, actionName); // Add the handler to an event map. fsm.Handlers += handler;
Thanks in advance, James.