So I have a custom generic model binder, that handle both T and Nullable<T>.
But I automatically create the bindigs via reflection. I search trhough the entire appdomain for enumeration flagged with specific attribute and I want to bind theese enums like this:
AppDomain
.CurrentDomain
.GetAssemblies()
.SelectMany(asm => asm.GetTypes())
.Where(
t =>
t.IsEnum &&
t.IsDefined(commandAttributeType, true) &&
!ModelBinders.Binders.ContainsKey(t))
.ToList()
.ForEach(t =>
{
ModelBinders.Binders.Add(t, new CommandModelBinder(t));
//the nullable version should go here
});
But here is the catch. I can't bind the Nullable<T> to CommandModelBinder.
I'm thinking the runtime code generation, but I never do this, and maybe there is other options on the market.
Any idea to achieve this?
Thanks,
Péter