problem with choice of class and namespace names in RazorGenorator.MSbuild

Jun 18, 2014 at 1:44 AM
I'm having a problem with the class and namespace names that are generated by RazorGenorator.MSBuild

With a razor file like this:
Views/Accounts/Mobile/Index.cshtml
I get
Namespace = Views.Accounts.Mobile
Class name = Index
Note that classical razor processing uses different choices:
Namespace = ASP
Class name = _Views_Accounts_Mobile__Index_cshtml
Is there any way run razorgenerator so that it names classes and namespaces the same way that
happens under MVC?



The difference I mention above causes trouble because of a nuance of
how C# handles namespaces. Specifically (TL;DR warning!!!) :
This line of C# code:

    Var x = new Accounts.Auditor();

has the compiler looking for a class "Accounts.Auditor".
This class does in fact exist somewhere, at "global::Accounts.Auditor".

But, early in the search for Accounts.Auditor, the C# compiler finds "Views.Accounts".

Auditor does not exist in Views.Accounts, so one might think that C# would continue its
search and eventually find global::Accounts.Auditor".

That does not happen. What C# actually does is something like "I have
found 'Accounts', there is no Auditor here, so FAIL-AND-EXIT."
So, the compile fails.

There are several one-off ways I can solve this, but I'm porting about 1000 razor files
to use RazorGenerator.MSbuild. More than 100 of them have this problem, and it
would be expensive to edit and test my changes, or created dozens of razorgenerator.directives.
Coordinator
Jun 18, 2014 at 3:02 PM
There is a way to change the namespace per file (@* Namespace: SomeNamespace *@), but I don't think there is a way to change the global algorithm. I seem to recall this coming up not so long ago but couldn't find the thread. Might need a global option to control this.
Jun 18, 2014 at 5:06 PM
Edited Jun 18, 2014 at 5:26 PM
Any of these options would be super helpful:

a. @* BuildMyClassNamesWereBuiltFromTheFilePath @
or
@
Generator : MvcViewUsingMvcViewStyleClassNames @

in other words, create class name based on source-file-directory-path, same as MVC

b. @
ObfuscateNamespacesName @
Namespace = V_i_e_w_s.A_c_c_o_u_n_t_s.M_o_b_i_l_e instead of Namespace = Views.Accounts.Mobile

c. @
NamespaceSegmentSuffix: foo @*
Namespace = Views_foo_.Accounts_foo_.Mobile_foo_

d. @* NamespaceSegmentSeparater: ___ @*
Namespace = Views___Accounts___Mobile___

It would also be totally cool if any of the above became the new default behavior but of course I don't need to ask for that.