Meet the Players
Now that you know how a Razor template gets turned into an executable class, it’s time to take a tour of the Razor API classes that make it all possible. The basic list is surprisingly short:
System.Web.Razor.Parser.RazorParser
RazorParser
executes the logic discussed in How Razor Parses Markup and Code, mapping a Razor template into an in-memory document that theRazorCodeGenerator
can consume. Despite its name,RazorParser
does not know anything about HTML or code languages such as C#. Instead,RazorParser
relies on other code and markup implementations to perform the actual parsing. For example, theMarkupParser
class knows how to interpret HTML markup, and theCSharpCodeParser
andVBCodeParser
classes know how to parse C# and VB.NET code, respectively.RazorParser
merely acts as the coordinator between various markup and code parsing implementations.System.Web.Razor.Generator.RazorCodeGenerator
The
RazorCodeGenerator
class contains the logic for generating .NET code fromRazorParser
’s output. LikeRazorParser
, theRazorCodeGenerator
class itself does not have any knowledge of any specific languages, only general knowledge of how to interpretRazorParser
output. UnlikeRazorParser
, however,RazorCodeGenerator
is an abstract base class from which language-specific implementations (such asCSharpRazorCodeGenerator
andVBRazorCodeGenerator
) derive. Razor API consumers reference the language-specific implementations that derive fromRazorCodeGenerator
, notRazorCodeGenerator ...
Get Programming Razor now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.