/// <inheritdoc /> public CompilationResult Compile([NotNull] RelativeFileInfo file) { GeneratorResults results; using (var inputStream = file.FileInfo.CreateReadStream()) { results = _razorHost.GenerateCode(file.RelativePath, inputStream); } if (!results.Success) { return(GetCompilationFailedResult(file, results.ParserErrors)); } return(_compilationService.Compile(file, results.GeneratedCode)); }
/// <inheritdoc /> public CompilationResult Compile([NotNull] RelativeFileInfo file) { GeneratorResults results; using (var inputStream = file.FileInfo.CreateReadStream()) { results = _razorHost.GenerateCode( file.RelativePath, inputStream); } if (!results.Success) { var messages = results.ParserErrors.Select(e => new CompilationMessage(e.Message)); return(CompilationResult.Failed(file.FileInfo, results.GeneratedCode, messages)); } return(_compilationService.Compile(file.FileInfo, results.GeneratedCode)); }
internal CompilationResult CompileCore(IFileInfo file) { GeneratorResults results; using (var inputStream = file.CreateReadStream()) { Contract.Assert(file.PhysicalPath.StartsWith(_appRoot, StringComparison.OrdinalIgnoreCase)); var rootRelativePath = file.PhysicalPath.Substring(_appRoot.Length); results = _razorHost.GenerateCode(rootRelativePath, inputStream); } if (!results.Success) { var messages = results.ParserErrors.Select(e => new CompilationMessage(e.Message)); return(CompilationResult.Failed(file, results.GeneratedCode, messages)); } return(_baseCompilationService.Compile(file, results.GeneratedCode)); }
protected virtual RazorFileInfo ParseView([NotNull] RelativeFileInfo fileInfo, [NotNull] IBeforeCompileContext context, [NotNull] CSharpParseOptions options) { using (var stream = fileInfo.FileInfo.CreateReadStream()) { var results = _host.GenerateCode(fileInfo.RelativePath, stream); foreach (var parserError in results.ParserErrors) { var diagnostic = parserError.ToDiagnostics(fileInfo.FileInfo.PhysicalPath); context.Diagnostics.Add(diagnostic); } var generatedCode = results.GeneratedCode; if (generatedCode != null) { var syntaxTree = SyntaxTreeGenerator.Generate(generatedCode, fileInfo.FileInfo.PhysicalPath, options); var fullTypeName = results.GetMainClassName(_host, syntaxTree); if (fullTypeName != null) { context.CSharpCompilation = context.CSharpCompilation.AddSyntaxTrees(syntaxTree); var hash = RazorFileHash.GetHash(fileInfo.FileInfo); return(new RazorFileInfo() { FullTypeName = fullTypeName, RelativePath = fileInfo.RelativePath, LastModified = fileInfo.FileInfo.LastModified, Length = fileInfo.FileInfo.Length, Hash = hash, }); } } } return(null); }
/// <inheritdoc /> public CompilationResult Compile([NotNull] RelativeFileInfo file) { GeneratorResults results; using (var inputStream = file.FileInfo.CreateReadStream()) { results = _razorHost.GenerateCode( file.RelativePath, inputStream); } if (!results.Success) { var messages = results.ParserErrors .Select(parseError => new RazorCompilationMessage(parseError, file.RelativePath)); var failure = new RazorCompilationFailure( file.RelativePath, ReadFileContentsSafely(file.FileInfo), messages); return(CompilationResult.Failed(failure)); } return(_compilationService.Compile(file, results.GeneratedCode)); }
/// <summary> /// Generate code for the Razor file at <paramref name="relativePath"/> with content /// <paramref name="inputStream"/>. /// </summary> /// <param name="relativePath"> /// The path of the Razor file relative to the root of the application. Used to generate line pragmas and /// calculate the class name of the generated type. /// </param> /// <param name="inputStream">A <see cref="Stream"/> that contains the Razor content.</param> /// <returns>A <see cref="GeneratorResults"/> instance containing results of code generation.</returns> protected virtual GeneratorResults GenerateCode(string relativePath, Stream inputStream) { return(_razorHost.GenerateCode(relativePath, inputStream)); }