Asp.net mvc 4 Override Razor CodeGeneration

Asp.net mvc 4 Override Razor CodeGeneration,asp.net-mvc-4,razor,Asp.net Mvc 4,Razor,I need to change the loginc of the View subclasses generated by Razor view engine. As I understood MVC parses the Razor cshtml file and generates IView subclass Render method which writes the html tags into writer object. In my case because environment/host will have more information(metadata) I want to make use of this. I need to step into where Razor parses an AST from cshtml and passes it to CodeGenerator. Currently I am trying to find that step in the aspnetwebstack source code. I

I need to change the loginc of the View subclasses generated by Razor view engine. As I understood MVC parses the Razor cshtml file and generates IView subclass Render method which writes the html tags into writer object. In my case because environment/host will have more information(metadata) I want to make use of this. I need to step into where Razor parses an AST from cshtml and passes it to CodeGenerator. Currently I am trying to find that step in the aspnetwebstack source code. I could not find that yet and I suspect that thease steps are intermingled so that there is not seperate get AST and generate code steps.


#1

What I have so far is this

Razor template engine parser returns an AST that contains Span and Block elements. Spans appear to be leaf nodes which. I did a little test code and the problem is span does not seperate different html nodes rather contains string of raw html till switch to C# code. For example:

<html><body><!-- Single statement block -->@{ var myMessage =   \"Hello World \"+123; }</body></html>

gives me this tree

* start block  Markup 
** span <html><body><!-- Single statement block -->
** start block  Statement : @{ var myMessage =   "Hello World "+666; }
*** span @
*** span {
*** span  var myMessage =        "Hello World "+123;
*** span }
** end block Statement
** span </body></html>
* end block Markup

Interesting thing is if the parser doe not provide information about html tags and merges continuous html parts into one string then how does the editor fold them according to nesting ?


#2

It seems that while building AST nodes parser attaches code generator for each of them.