title: C# Type parameter as Generic declaration
body: <p>I am getting an error when trying to use a Type parameter when specifying the Type for a generic method.</p>
  
  <blockquote>
    <p>Error: 'JsonFilter.JsonDataType' is a 'property' but is used like a 'type'</p>
  </blockquote>
  
  <pre><code>public class JsonFilter : ActionFilterAttribute
  {
      public Type JsonDataType { get; set; }
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
          ...
          JavaScriptSerializer jss = new JavaScriptSerializer();
          var result = jss.Deserialize&lt;JsonDataType&gt;(inputContent);//Error here
          ...
  </code></pre>
  
  <p>New Code</p>
  
  <pre><code>...
  JavaScriptSerializer jss = new JavaScriptSerializer();
  MethodInfo method = jss.GetType()
                 .GetMethod("Deserialize")
                 .MakeGenericMethod(new Type[] { JsonDataType });
  var result = method.Invoke(jss, new object[] { inputContent });
  filterContext.ActionParameters[Param] = result;
  ...
  </code></pre>
  
  <p>Reflection saves the day.  Thanks @Jason for the explanation that when type is specified as part of generic method ( &lt;<em>Typename</em>> ), then it gets compiled into bytes.  Whereas when as property, it can be any type, only determinable at runtime.</p>
  
  <p>UPDATE</p>
  
  <p>For this specific problem, the following code is more concise.</p>
  
  <pre><code>var o = new DataContractJsonSerializer(JsonDataType).ReadObject(
      filterContext.HttpContext.Request.InputStream);
  filterContext.ActionParameters[Param] = o;
  </code></pre>