I need to call methods for a type through reflection using C #.
At runtime, my data will consist of a dictionary containing name / value pairs. The names in the dictionary will correspond to the names of the parameters in the method that I will call. Also, at runtime, I will have an arbitrary assembly type name and method name. During development, I will not know the type and method other than that the method will accept a variable number of parameters like int, string, DateTime, bool, int [], string [], DateTime [] or bool [].
I have no problem so that I can instantiate the type using reflection and call the method. I am stuck at the point where I need to convert the string values ββin my dictionary to the appropriate type needed by the method when called:
someMethodInfo.Invoke(instance, new [] { ... })
I know that I probably need to list through MethodInfo.GetParameters () and perform type conversion for each parameter. I am trying to figure out how to do this, and ideally, how to do it effectively.
My research so far has included digging into the MVC source code, as it does something similar when passing form values ββto ActionMethod. I found ActionMethodDispatcher but uses LINQ Expressions that I am not familiar with.
I also looked at similar questions on SO, but did not find anything that answered my question.
I would welcome any pointers to a solution.
Nik Kalyani
source share