title: Generic Model Binder using reflection
body: <p>I'm trying to build a generic model binder that uses reflection to assign properties to a specified type of object retrieved from the BindingContext.  So something like this:</p>
  
  <pre><code>public class ModelBinder : IModelBinder
  {
      public object BindModel&lt;T, K&gt; (ControllerContext controllerContext, ModelBindingContext bindingContext)
          where T : class, new()
          where K : class
      {
          Type ObjectType = typeof(T);
          Type InterfaceType = typeof(K);
          T obj = new T();
  
          foreach (var Property in ObjectType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance))
          {
              Type PropertyType = Property.PropertyType;
  
              // checks if property is a custom data object
              if (!(PropertyType.GetGenericArguments().Count() &gt; 0 &amp;&amp; PropertyType.GetGenericArguments()[0].GetInterfaces().Contains(InterfaceType)))
              {
                  Property.SetValue(obj, bindingContext.ValueProvider.GetValue(Property.Name), null);   
              }
          }
  
          return obj;
      }
  </code></pre>
  
  <p>Obviously this doesn't work as it isn't correctly implementing the IModelBinder interface.  Is something like this possible?</p>
  
  <p>Edit:</p>
  
  <p>To expand on why I am doing this, our objects use a lot of different custom objects.  For instance, the Class object: </p>
  
  <pre><code>public class Class : ModelBase&lt;Class&gt;
  {
      public Class () { }
  
      public virtual string ClassDescription { get; set; }
      public virtual string ClassName { get; set; }
      public virtual LookUp ClassType { get; set; }
      public virtual double Credits { get; set; }
      public virtual bool Documents { get; set; }
      public virtual LookUp PracticeArea { get; set; }
  }
  </code></pre>
  
  <p>uses the LookUp class:</p>
  
  <pre><code>public class LookUp : ModelBase&lt;LookUp&gt;
  {
      public LookUp () { }
  
      public virtual string DisplayName { get; set; }
      public virtual LookUpType Type { get; set; }
  }
  </code></pre>
  
  <p> dropdowns are used for LookUps and other objects so my custom model binder for Class/Create would do something like: </p>
  
  <pre><code>LookUp ClassType = LookUp.Load(long.Parse(bindingContext.ValueProvider.GetValue("ClassType").AttemptedValue))
  </code></pre>
  
  <p>I don't see how something like this can be dealt with using the DefaultModelBinder.</p>