///////////////////////////////////////////////////////////////////////////// private string Runner( string text, bool returnSource, RazorRunnerException.RunHow runContext ) { // ****** //dynamic context = new ExpandoObject(); //context.Version = 2.0; // ****** var asmId = string.Empty; var result = string.Empty; var reader = new StringReader( text ); // ****** // as arguments to ctor pass the PrePostHandler() and a method to customize // the host and whatever else // // for the host we set the names for section, etc var razor = new RazorEngine<NmpRazorTemplateBase>( DefaultNamespaces, PrePostRenderHandler, CreateHostHandler ); razor.SetError(); try { asmId = razor.ParseAndCompileTemplate( assemblyPaths, reader ); } catch ( Exception ex ) { ThreadContext.MacroError( "error Parsing and Compiling Razor template: {0}", ex.Message ); } if( null == asmId ) { // // error // const string ErrMsg = "Razor failed to compile the generated source."; throw new RazorRunnerException( runContext, ErrMsg, razor.ErrorMessage, razor.LastGeneratedCode ); } // ****** try { result = razor.RenderTemplateFromAssembly( asmId, null ); } catch ( Exception ex ) { ThreadContext.MacroError( "error Rendering Razor Template from Assembly template: {0}", ex.Message ); } if( null == result ) { const string ErrMsg = "Razor failed to execute the template."; throw new RazorRunnerException( runContext, ErrMsg, razor.ErrorMessage, razor.LastGeneratedCode ); } // ****** if( RazorRunnerException.RunHow.Run == runContext ) { // // (#block `razor' // } // ****** return FileReader.FixText( returnSource ? RazorRunnerException.AddLineNumbers(razor.LastGeneratedCode) : result ); }