title: How to use a Generic Type in a Model Binder?
body: <p>On ASP.NET Core I have the following model:</p>
  
  <pre><code>public class Model {
    public Filter&lt;Int32&gt; filter { get; set; }
  }
  </code></pre>
  
  <p>Where Filter is the following:</p>
  
  <pre><code>public class Filter&lt;T&gt; {
    public T Value { get; set; }
    public Filter(T value) {
      Value = value;
    }
  } 
  
  public static class Filter {
    public static Boolean TryParse&lt;T&gt;(String value, out Filter&lt;T&gt; filter) {
      // Try parse code
    }
  }
  </code></pre>
  
  <p>I need to create a ModelBinder to bind properties of type Filter:</p>
  
  <pre><code>public class FilterModelBinder : IModelBinder {
  
    public Task BindModelAsync(ModelBindingContext bindingContext) {
  
      if (bindingContext == null)            
        throw new ArgumentNullException(nameof(bindingContext));
  
      String modelName = bindingContext.ModelName;
  
      ValueProviderResult valueProviderResult = bindingContext.ValueProvider.GetValue(modelName);
  
      if (valueProviderResult == ValueProviderResult.None)
        return Task.CompletedTask;
  
      bindingContext.ModelState.SetModelValue(modelName, valueProviderResult);
  
      String value = valueProviderResult.FirstValue;
  
      if (String.IsNullOrEmpty(value))
        return Task.CompletedTask;
  
      if (!Filter.TryParse(value, out Filter&lt;T&gt; filter)) {
  
        bindingContext.ModelState.TryAddModelError(modelName, "Value is not of type Filter");
        return Task.CompletedTask;
  
      } 
  
      bindingContext.Result = ModelBindingResult.Success(filter);
      return Task.CompletedTask;
  
    }
  
  }
  </code></pre>
  
  <p>My problem is how to apply the TryParse to a generic filter:</p>
  
  <pre><code>Filter.TryParse(value, out Filter&lt;T&gt; filter)
  </code></pre>
  
  <p>How to use a Generic type in the ModelBinder?</p>