title: How to do automatic type conversion for parameters when invoking a method using reflection in C#?
body: <p>I have a need to invoke methods on a type through reflection using C#.</p>
  
  <p>At run-time, my data will consist of a Dictionary containing name/value pairs. The names in the Dictionary will correspond to parameter names on the method I will invoke. Also, at run-time, I will have an arbitrary assembly qualified type name and a method name. At design time, I will have no knowledge of the type and the method other than that the method will accept a variable number of parameters of type int, string, DateTime, bool, int[], string[], DateTime[] or bool[].</p>
  
  <p>I have no problem getting to the point where I can create an instance of the type using reflection and invoke the method. I am stuck at the point where I have to convert the string values in my dictionary to the appropriate type needed by the method when I call:</p>
  
  <pre><code>someMethodInfo.Invoke(instance, new [] { ... })
  </code></pre>
  
  <p>I know that I need to probably enumerate through MethodInfo.GetParameters() and perform the type conversion for each parameter. What I am trying to figure out is how to do this, and ideally, how to do it efficiently.</p>
  
  <p>My research so far has involved digging into the MVC source code as it does something similar when passing form values to an ActionMethod. I found <a href="http://aspnet.codeplex.com/SourceControl/changeset/view/68345#266435" rel="nofollow">ActionMethodDispatcher</a> but it uses LINQ Expressions, with which I am unfamiliar.</p>
  
  <p>I also looked at similar questions on SO, but did not find anything that answers my question.</p>
  
  <p>I would welcome any pointers to a solution.</p>