• [源码学习]记录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();
        }
    }


  • 相关阅读:
    JVM调优
    Java堆空间的划分:新生代、老年代
    说一下 jvm 有哪些垃圾回收器?
    JVM的垃圾回收算法有哪些
    订单并发处理--悲观锁和乐观锁、任务队列以及订单模块开发流程
    MySQL数据库的四种事务隔离级别以及事务的并发问题(脏读/不可重复读/幻读)
    Python面试总结复习(四)
    Python面试总结复习(三)
    Django表设计,多表操作复习
    python面试总结复习(二)
  • 原文地址:https://www.cnblogs.com/llcto/p/2794766.html
Copyright © 2020-2023  润新知