Reputation: 2867
Okay, so I currently have an HTMLHelper like-so:
public static MvcHtmlString BackLink<TVM>(this HtmlHelper<TVM> helper, ...)
where TVM : VM
// Usage:
@Html.BackLink(...)
Is there a way to do this, while maintaining the usage from above?
public static MvcHtmlString BackLink<TVM, TM>(this HtmlHelper<TVM> helper, ...)
where TVM : VM<TM> // Where VM<TM> : ISaveState<TM>
// Usage:
@{ String link = Html.BackLink<TM>(...); }
@link
// Doesn't work :(
@Html.BackLink<TM>(...)
VM is a non-generic version of VM. ISaveState is a non-generic version of ISaveState where TVM is the object that implements it (at least in usage).
I've tried the second bit of code, and after many attempts to make non-generic versions of all my generic stuff only to realize that the conversions between things (despite seeming simple) wasn't simple.
Is it possible to supply an extra Generic type parameter to an HTML Helper (in Razor) without having to store it in a variable to display it? i.e. @Html.BackLink<TM>(...)
Upvotes: 0
Views: 122
Reputation: 152566
You can't partially infer generic parameters. Since you don't have any parameters that let the compiler infer the TM
type parameter, you'll need to specify both generic parameters:
// Usage:
@{ String link = Html.BackLink<TVM,TM>(...); }
Upvotes: 1