Exemplo n.º 1
0
        public RazorCSharp Generate(string path)
        {
            var razor  = _templateEngine.CreateCodeDocument(path);
            var csharp = _templateEngine.GenerateCode(razor);

            return(new RazorCSharp(csharp, _compilationOptions, _references, _emitOptions));
        }
Exemplo n.º 2
0
        protected virtual CompiledViewDescriptor CompileAndEmit(string relativePath)
        {
            var codeDocument   = _templateEngine.CreateCodeDocument(relativePath);
            var cSharpDocument = _templateEngine.GenerateCode(codeDocument);

            if (cSharpDocument.Diagnostics.Count > 0)
            {
                throw new Exception();
            }

            var generatedAssembly = CompileAndEmit(codeDocument, cSharpDocument.GeneratedCode);
            var viewAttribute     = generatedAssembly.GetCustomAttribute <RazorViewAttribute>();

            return(new CompiledViewDescriptor
            {
                ViewAttribute = viewAttribute,
                RelativePath = relativePath,
            });
        }