Ejemplo n.º 1
0
        private async Task <string> ParseResultAsync <T>(T model, RazorCompilerResult razorCompilerResult)
        {
            if (razorCompilerResult.ProcessingException != null)
            {
                throw razorCompilerResult.ProcessingException;
            }

            var csharpCompilerResult = compiler.CompileToType(razorCompilerResult.GeneratedText);

            if (csharpCompilerResult.ProcessingException != null)
            {
                throw csharpCompilerResult.ProcessingException;
            }

            return(await razorViewExecutor.ExecuteAsync <T>(csharpCompilerResult.CompiledType, model));
        }
Ejemplo n.º 2
0
        private RazorCompilerResult GetCompilerResult(
            RazorTemplateEngine templateEngine,
            RazorProjectItem projectItem)
        {
            var cSharpDocument = templateEngine.GenerateCode(projectItem);

            var result = new RazorCompilerResult();

            if (cSharpDocument.Diagnostics.Any())
            {
                var messages = cSharpDocument.Diagnostics.Select(d => d.GetMessage());
                result.ProcessingException = new RazorCompilerException(messages, cSharpDocument.GeneratedCode);
            }
            else
            {
                result.GeneratedText = cSharpDocument.GeneratedCode;
            }
            return(result);
        }