internal static WebPageRazorHost CreateHostFromConfigCore(RazorWebSectionGroup config, string virtualPath, string physicalPath) { // Use the virtual path to select a host environment for the generated code // Do this check here because the App_Code host can't be overridden. // Make the path app relative virtualPath = EnsureAppRelative(virtualPath); if (virtualPath.StartsWith("~/App_Code", StringComparison.OrdinalIgnoreCase)) // change to app-code // Under App_Code => It's a Web Code file { return(new WebCodeRazorHost(virtualPath, physicalPath)); } WebRazorHostFactory factory = null; if (config != null && config.Host != null && !String.IsNullOrEmpty(config.Host.FactoryType)) { Func <WebRazorHostFactory> factoryCreator = _factories.GetOrAdd(config.Host.FactoryType, CreateFactory); Debug.Assert(factoryCreator != null); // CreateFactory should throw if there's an error creating the factory factory = factoryCreator(); } WebPageRazorHost host = (factory ?? new WebRazorHostFactory()).CreateHost(virtualPath, physicalPath); if (config != null && config.Pages != null) { ApplyConfigurationToHost(config.Pages, host); } return(host); }
public static void ApplyConfigurationToHost(RazorPagesSection config, WebPageRazorHost host) { host.DefaultPageBaseClass = config.BaseType; // Add imports foreach (string import in config.Namespaces.OfType <NamespaceInfo>().Select(ns => ns.Namespace)) { host.NamespaceImports.Add(import); } }
public static void ApplyConfigurationToHost(RazorPagesSection config, WebPageRazorHost host) { host.DefaultPageBaseClass = config.BaseType; // Add imports foreach (string import in config.Namespaces.OfType<NamespaceInfo>().Select(ns => ns.Namespace)) { host.NamespaceImports.Add(import); } }