protected override void OnBeforeCompilePath(CompilingPathEventArgs args) { base.OnBeforeCompilePath(args); if (!(args.Host is RazorHost)) { args.Host = RazorHost.CreateFromAnother(args.Host); } }
static void RazorBuildProvider_CompilingPath(object sender, CompilingPathEventArgs e) { // If MVC-Razor was already going to handle this //if (e.Host is MvcWebPageRazorHost) //{ // // Switch it out for our custom host. // e.Host = new MyRazorHost(e.Host.VirtualPath, e.Host.PhysicalPath); //} }
private Type GetTypeFromVirtualPathNoCache(string virtualPath) { using (DoProfileStep($"{nameof(RoslynRazorViewEngine)}: Compiling {virtualPath}")) { OnCodeGenerationStarted(); var args = new CompilingPathEventArgs(virtualPath, WebRazorHostFactory.CreateHostFromConfig(virtualPath)); OnBeforeCompilePath(args); var host = args.Host; var razorResult = RunRazorGenerator(virtualPath, host); var syntaxTree = GetSyntaxTree(host, razorResult); var assembly = CompileToAssembly(host, syntaxTree); return(assembly.GetType($"{host.DefaultNamespace}.{host.DefaultClassName}")); } }
/// <summary> /// Raises the <see cref="CompilingPath"/> event. /// </summary> /// <param name="args"></param> protected virtual void OnBeforeCompilePath(CompilingPathEventArgs args) => CompilingPath?.Invoke(this, args);