[源码学习]记录RazorParser Call Stack

SystemWebMvc\Mvc\VirtualPathProviderViewEngine.cs

继承关系 RazorViewEngine : BuildManagerViewEngine : VirtualPathProviderViewEngine

VirtualPathProviderViewEngine类

FindView方法 134行

string viewPath = GetPath(controllerContext, ViewLocationFormats, AreaViewLocationFormats, "ViewLocationFormats", viewName, controllerName, _cacheKeyPrefix_View, useCache, out viewLocationsSearched);
 
GetPath方法 167行

return (nameRepresentsPath) ?
                GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations) :
                GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, cacheKey, ref searchedLocations);
 

GetPathFromGeneralName方法 180行

if (FileExists(controllerContext, virtualPath))


BuildManagerViewEngine 类

FileExists方法 42行

return BuildManager.FileExists(virtualPath);


BuildManagerWrapper 类

FileExists方法 8行

return BuildManager.GetObjectFactory(virtualPath, false) != null;


********************

 

只有注册了Rozor的BuildProcider,BuildManager才会调用
 

 

System.Web.WebPages.Razor\Properties\AssemblyInfo.cs

13行

[assembly: PreApplicationStartMethod(typeof(PreApplicationStartCode), "Start")]


System.Web.WebPages.Razor\PreApplicationStartCode.cs

26行

BuildProvider.RegisterBuildProvider(".cshtml"typeof(RazorBuildProvider));
BuildProvider.RegisterBuildProvider(".vbhtml"typeof(RazorBuildProvider));


********************

RazorBuildProvider 类

CodeCompilerType属性 98行

EnsureGeneratedCode();


EnsureGeneratedCode方法 166行

RazorTemplateEngine engine = new RazorTemplateEngine(Host);
GeneratorResults results = null;
using (TextReader reader = InternalOpenReader()) {
    results = engine.GenerateCode(reader, className: null, rootNamespace: null, sourceFileName: Host.PhysicalPath);
}



System.Web.Razor\RazorTemplateEngine.cs

126行

 

public GeneratorResults GenerateCode(TextReader input, string className, string rootNamespace, string sourceFileName) {
     return GenerateCode(input, className, rootNamespace, sourceFileName, null);
}


130行

[SuppressMessage("Microsoft.Reliability""CA2000:Dispose objects before losing scope", Justification = "Input object would be disposed if we dispose the wrapper.  We don't own the input so we don't want to dispose it")]
public GeneratorResults GenerateCode(TextReader input, string className, string rootNamespace, string sourceFileName, CancellationToken? cancelToken) {
    return GenerateCodeCore(new BufferingTextReader(input), className, rootNamespace, sourceFileName, cancelToken);
}


148行

RazorParser parser = CreateParser();
Debug.Assert(parser != null);
parser.Parse(input, consumer);


System.Web.Razor\Parser\RazorParser.cs

35行

public virtual void Parse(LookaheadTextReader input, ParserVisitor visitor) {
    // Setup the parser context
    ParserContext context = new ParserContext(input, CodeParser, MarkupParser, MarkupParser, visitor) {
        DesignTimeMode = DesignTimeMode
    };

    MarkupParser.Context = context;
    CodeParser.Context = context;

    // Execute the context
    try {
        MarkupParser.ParseDocument();
    }
    finally {
        context.OnComplete();
    }
}


posted @ 2012-11-29 15:39  虾吵吵  阅读(381)  评论(0编辑  收藏  举报