I have a frustrating problem. I’m building a view engine in ASP.NET MVC and are implementing the interface IViewEngine. In one of the methods I’m trying to dynamically figure out the type of the result of a view. Sometimes the result is a template (with the type Template<‘key>). The keys are used to target a placeholder in the template, and the idea is to use a discriminated union, potentially unique for each web site. It could look like this:
type MasterKey = | HeadContent | HeaderContent | MainContent | FooterContent
let MasterTemplate : Template<MasterKeys> = ...
Now, the problem is this: since I’m implementing an interface, I have no control over the method signature. Since I can not add a generic type parameter, the ‘a will be converted to an obj and the Template will not be a match below:
match result with
| :? foo -> ...
| :? bar -> ...
| :? Template<'a> -> ...
Any ideas?
Can you make the whole view engine class generic, according to the type of
'keyit uses? Indivudual projects will need to inherit from your view engine class and specify the type of key in the process.