/// <summary> /// Gets an ordered <see cref="IReadOnlyList{T}"/> of parsed <see cref="CodeTree"/> for each /// <c>_GlobalImport</c> that is applicable to the page located at <paramref name="pagePath"/>. The list is /// ordered so that the <see cref="CodeTree"/> for the <c>_GlobalImport</c> closest to the /// <paramref name="pagePath"/> in the file system appears first. /// </summary> /// <param name="pagePath">The path of the page to locate inherited chunks for.</param> /// <returns>A <see cref="IReadOnlyList{CodeTree}"/> of parsed <c>_GlobalImport</c> /// <see cref="CodeTree"/>s.</returns> public virtual IReadOnlyList <CodeTree> GetInheritedCodeTrees([NotNull] string pagePath) { var inheritedCodeTrees = new List <CodeTree>(); var templateEngine = new RazorTemplateEngine(_razorHost); foreach (var globalImportPath in ViewHierarchyUtility.GetGlobalImportLocations(pagePath)) { // globalImportPath contains the app-relative path of the _GlobalImport. // Since the parsing of a _GlobalImport would cause parent _GlobalImports to be parsed // we need to ensure the paths are app-relative to allow the GetGlobalFileLocations // for the current _GlobalImport to succeed. var codeTree = _codeTreeCache.GetOrAdd(globalImportPath, fileInfo => ParseViewFile(templateEngine, fileInfo, globalImportPath)); if (codeTree != null) { inheritedCodeTrees.Add(codeTree); } } return(inheritedCodeTrees); }