I get the class name and method name as well as parameters via query string. I don’t know what is coming so I can’t say lets create this instance or that instance to pass it MethodInfo Invoke method so I need a generic solution. Here is the problem :
string className = Request.QueryString["className"];
string actionMethod = Request.QueryString["actionName"];
so I have to invoke a class method by the info above :
System.Reflection.MethodInfo info = Type.GetType(className).GetMethod(actionMethod);
info.Invoke(obj, null);
But since I don’t know what it is coming from the QueryString I can’t create an instance of the class of which I want to invoke the method.
How can I get over this problem…
If you know the assembly that contains the class you are invoking, you can use
Assembly.CreateInstance(string)to create your instance of the class.Code not tested
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.createinstance.aspx