I'm examining a scenario in which I'd be using RazorGenerator to share my MVC views between two different MVC sites, and I was wondering if it would be possible to also put partial implementations of a controller in another assembly and have T4MVC pick up on methods defined in the other assembly.
So, for instance, something like this:
MVC Library/HomeController.cs
namespace SharedNameSpace ...
public partial class HomeController
{
public virtual ActionResult SomeSharedAction() { return View(); }
}
MVC ProjectA/HomeController.cs - ProjectA has reference to "MVC Library" project
namespace SharedNameSpace ...
public partial class HomeController
{
public virtual ActionResult IndexA()
{
return Partial(MVC.Home.SomeSharedAction(), new { });
}
}
I tried looking at the .tt
file to determine how the methods are discovered by T4MVC, but had some trouble discerning this. Here's some of the relevant code I found:
foreach (CodeFunction2 method in GetMethods(type))
{
...
controllerInfo.ActionMethods.Add(new ActionMethodInfo(method, current));
}
static IEnumerable<CodeFunction2> GetMethods(CodeClass2 codeClass)
{
// Only look at regular method (e.g. ignore things like contructors)
return codeClass.Members.OfType<CodeFunction2>()
.Where(f => f.FunctionKind == vsCMFunction.vsCMFunctionFunction);
}
... But I couldn't find the definition of a CodeClass2
to determine how its Members
is determined. (Is CodeClass2
a generic type or something?) Is there a way this could be altered to find methods for a partial class that were defined in a referenced assembly? Not sure if T4 has access to all the features of reflection or not.
Edit: I found some more info on CodeClass2
, apparently it's an MS type, which was unexpected due to the name. MSDN shows latest documentation for vs2008 though