No constants generated by T4MVC?

Why are there no constant lines in the T4MVC generated code? My guess would be to copy constant compile-time values ​​...

But adding constants to the generated code would allow using the created T4MVC attributes in the attributes.

I am thinking of something like this:

Paste @line 400:

public const String ControllerNameCONST = @"<#=controller.ClassName #>"; 

Paste @line 445:

  [<#= GeneratedCode #>, DebuggerNonUserCode] public static class ActionNamesCONST { <#foreach (var method in controller.ActionMethodsWithUniqueNames) { #> <# if (UseLowercaseRoutes) { #> public const string <#=method.ActionName #> = (<#=method.ActionNameValueExpression #>).ToLowerInvariant(); <# } else { #> public const string <#=method.ActionName #> = <#=method.ActionNameValueExpression #>; <# } } #> } 

So, someone can use it like this:

 [SomeAttribute(HomeController.ControllerNameCONST)] //instead of [SomeAttribute("Home")] //or [SomeAttribute(HomeController.ActionNamesCONST.SomeAction)] //instead of [SomeAttribute("SomeAction")] 

Edit: use it as an autocomplete attribute for the model, so you can specify a β€œtarget” controller and action on the model. Although it can rework the autocomplete attribute to take the ActionResult parameter as a parameter instead of the controller + action name ...

+4
source share
1 answer

Update (12/7/2011): this problem has now been fixed (in 2.6.65). See http://mvccontrib.codeplex.com/workitem/7177 .


T4MVC generates many constants. eg.

For controller name: MVC.Home.Name

For action names: MVC.Home.ActionNames.About

For view names: MVC.Home.Views.About

+5
source

All Articles