0

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

DLeh
  • 23,806
  • 16
  • 84
  • 128
  • I'm not sure if this person is asking for the same thing as this question, but I found this link which seems relevant https://t4mvc.codeplex.com/discussions/570079 – DLeh Dec 29 '14 at 19:52

1 Answers1

0

I realized that one of my assumptions was incorrect, and that you cannot have partial classes declared across assemblies, so the desired effect is impossible for other reasons.

Reference: https://stackoverflow.com/a/309944/526704

Community
  • 1
  • 1
DLeh
  • 23,806
  • 16
  • 84
  • 128