Reputation: 17004
I currently want to write a generic extension method. If every generic type is availible in the parameters, I do not need to define the generic types:
//Extension Method
public static GridBoundColumnBuilder<TModel>
BoundEnum<TModel, TValue>(this GridColumnFactory<TModel> factory,
Expression<Func<TModel, TValue>> expression);
//I can call It this way, whitout setting <TModel, TValue>
columns.BoundEnum(c => c.SomeProp);
If I want to add a generic type, that is not covered in the parameters, I need to set <TModel, TValue>
:
//Extension Method
public static GridBoundColumnBuilder<TModel>
BoundEnum<TModel, TValue, TEnum>(this GridColumnFactory<TModel> factory,
Expression<Func<TModel, TValue>> expression)
//How it works:
columns.BoundEnum<TModel, TValue, TEnum>(c => c.SomeProp);
Is there a way that I can only write this?
columns.BoundEnum<TEnum>(c => c.SomeProp);
Edit: This is the full Method:
public static GridBoundColumnBuilder<TModel>
BoundEnum<TModel, TValue, TEnum>(this GridColumnFactory<TModel> factory,
Expression<Func<TModel, TValue>> expression)
where TModel : class
where TEnum : struct, IComparable
{
return factory.ForeignKey(expression, EnumHelper.ToSelectList<TEnum>());
}
Upvotes: 2
Views: 122
Reputation: 62472
If the compiler cannot infer all generic types then you have to pass them all. There's no support for partial inference.
Upvotes: 1