title: Passing anonymous type as method parameters
body: <p>In my plugin architecture I am currently passing a plugin name (string), method name (string) and parameters (object array) to my plugin service to execute the specified method and return the result (of type T).</p>
  
  <p>The plugin service's execute method can be seen below:</p>
  
  <pre><code>public TResult Execute&lt;TResult&gt;(string pluginName, string operation, params object[] input) {
      MethodInfo method = null;
      TResult result = default(TResult);
  
      var plugin = _plugins.Enabled().FirstOrDefault(x =&gt; x.GetType().Name.Equals(pluginName,  StringComparison.InvariantCultureIgnoreCase));
  
      if (plugin != null) {
          method = plugin.GetType().GetMethods().FirstOrDefault(x =&gt; x.Name == operation);
          if (method != null) {
              result = (TResult)method.Invoke(plugin, input);
          }
      }
      return result;
    }
  </code></pre>
  
  <p>An example usage:</p>
  
  <pre><code>var url = AppHelper.PluginService.Execute&lt;string&gt;(
      "ImagePlugin",
      "GetImageUrl",
      new object[] { image, size });
  </code></pre>
  
  <p>What I would rather do is pass in an anonymous type instead (as I think this is more readable) i.e.</p>
  
  <pre><code>var url = AppHelper.PluginService.Execute&lt;string&gt;(
      "ImagePlugin",
      "GetImageUrl",
      new { image = image, targetSize = size });
  </code></pre>
  
  <p>How would I change my Execute method to map the anonymous type properties to my plugin method parameters?</p>
  
  <p>I had considered using the new dynamic type in .net 4.0 but I prefer to define my parameters on the plugin method rather than accepting one dynamic object.</p>
  
  <p>Thanks
  Ben</p>
  
  <p>[Update]</p>
  
  <p>After looking through the ASP.NET MVC source code it seems simple enough to pull the anonymous type into an object dictionary e.g. RouteValueDictionary.
  With the help of reflection a linq expression is created dynamically. Although its a good implementation, I didn't really want all this extra complexity.</p>
  
  <p>As per the comment below, I can achieve readability just by specifying my parameters inline (no need for the object array declaration):</p>
  
  <pre><code>var url = AppHelper.PluginService.Execute&lt;string&gt;("ImagePlugin", "GetImageUrl", image, size);
  </code></pre>