Task Actions from derrived types

Nov 15, 2014 at 4:32 PM
The Task support in T4MVC works quite well, until you start using items that are not explicitly ActionType.

Look at this code from the source:
            // We only support action methods that return an ActionResult and Task<ActionResult> derived types
            if (!method.Type.CodeType.get_IsDerivedFrom("System.Web.Mvc.ActionResult") && method.Type.CodeType.FullName !="System.Threading.Tasks.Task<System.Web.Mvc.ActionResult>")
                // Comment out warning, as it's more annoying than helpful
                //Warning(String.Format("{0} doesn't support {1}.{2} because it doesn't return a supported {3} type", T4FileName, type.Name, method.Name, method.Type.CodeType.FullName));
It only supports Task<ActionResult>, not for example Task<JsonResult> even though it derives from ActionResult. You can see the code does an explicit text compare. This compare prohibits it from generating any code, but if it did get past this, there are a few other places that do this same kind of compare.

What we need to do is to check something like this:
var genericType = abc.GetType().GetTypeInfo().GenericTypeArguments[0]; and then check IsDerivedFrom on the generic type. The code above is normal runtime code, not sure how or if we can even do it.