/// <summary> /// Gets the Razor page for an input document stream. This is roughly modeled on /// DefaultRazorPageFactory and CompilerCache. Note that we don't actually bother /// with caching the page if it's from a live stream. /// </summary> private IRazorPage GetPageFromStream(string relativePath, Stream stream, IFileProvider rootFileProvider, IRazorCompilationService razorCompilationService) { if (relativePath.StartsWith("~/", StringComparison.Ordinal)) { // For tilde slash paths, drop the leading ~ to make it work with the underlying IFileProvider. relativePath = relativePath.Substring(1); } // Get the file info by combining the stream content with info found at the document's original location (if any) IFileInfo fileInfo = new StreamFileInfo(rootFileProvider.GetFileInfo(relativePath), stream); RelativeFileInfo relativeFileInfo = new RelativeFileInfo(fileInfo, relativePath); // Create the compilation CompilationResult compilationResult = razorCompilationService.Compile(relativeFileInfo); compilationResult.EnsureSuccessful(); // Create and return the page // We're not actually using the cache, but the CompilerCacheResult ctor contains the logic to create the page factory CompilerCacheResult compilerCacheResult = new CompilerCacheResult(relativePath, compilationResult, Array.Empty <IChangeToken>()); return(compilerCacheResult.PageFactory()); }