/// <summary> /// Initialises a new instance of <see cref="TemplateServiceConfiguration"/>. /// </summary> public TemplateServiceConfiguration() { // Read configuration values from App.config / Web.config // and fallback to appropriate defaults. var xmlConfig = new XmlTemplateServiceConfiguration(); Activator = xmlConfig.Activator ?? new DefaultActivator(); CompilerServiceFactory = xmlConfig.CompilerServiceFactory ?? new DefaultCompilerServiceFactory(); EncodedStringFactory = xmlConfig.EncodedStringFactory ?? new HtmlEncodedStringFactory(); #if !RAZOR4 CodeInspectors = xmlConfig.CodeInspectors != null ? xmlConfig.CodeInspectors.ToList() : new List<ICodeInspector>(); #endif Language = xmlConfig.Language; ReferenceResolver = xmlConfig.ReferenceResolver ?? new UseCurrentAssembliesReferenceResolver(); CachingProvider = xmlConfig.CachingProvider ?? new DefaultCachingProvider(); Resolver = xmlConfig.Resolver; TemplateManager = xmlConfig.TemplateManager ?? new DelegateTemplateManager(name => { throw new ArgumentException( string.Format( "Please either set a template manager to resolve templates or add the template '{0}'!", name)); }); Namespaces = new HashSet<string> { "System", "System.Collections.Generic", "System.Linq" }; Namespaces.UnionWith(xmlConfig.Namespaces); }
/// <summary> /// Initialises a new instance of <see cref="TemplateServiceConfiguration"/>. /// </summary> public TemplateServiceConfiguration() { // Read configuration values from App.config / Web.config // and fallback to appropriate defaults. var xmlConfig = new XmlTemplateServiceConfiguration(); Activator = xmlConfig.Activator ?? new DefaultActivator(); CompilerServiceFactory = xmlConfig.CompilerServiceFactory ?? new DefaultCompilerServiceFactory(); EncodedStringFactory = xmlConfig.EncodedStringFactory ?? new HtmlEncodedStringFactory(); #if !RAZOR4 CodeInspectors = xmlConfig.CodeInspectors != null?xmlConfig.CodeInspectors.ToList() : new List <ICodeInspector>(); #endif Language = xmlConfig.Language; ReferenceResolver = xmlConfig.ReferenceResolver ?? new UseCurrentAssembliesReferenceResolver(); CachingProvider = xmlConfig.CachingProvider ?? new DefaultCachingProvider(); Resolver = xmlConfig.Resolver; TemplateManager = xmlConfig.TemplateManager ?? new DelegateTemplateManager(name => { throw new ArgumentException( string.Format( "Please either set a template manager to resolve templates or add the template '{0}'!", name)); }); Namespaces = new HashSet <string> { "System", "System.Collections.Generic", "System.Linq" }; Namespaces.UnionWith(xmlConfig.Namespaces); }
static void Main(string[] args) { var config = new TemplateServiceConfiguration(); var xml = new XmlTemplateServiceConfiguration("myapp"); foreach (var ns in xml.Namespaces) { config.Namespaces.Add(ns); } Engine.Razor = RazorEngineService.Create(config); if (!Engine.Razor.IsTemplateCached("test", null)) { } }
/// <summary> /// Initialises a new instance of <see cref="TemplateServiceConfiguration"/>. /// </summary> public TemplateServiceConfiguration() { // Read configuration values from App.config / Web.config // and fallback to appropriate defaults. var xmlConfig = new XmlTemplateServiceConfiguration(); Activator = xmlConfig.Activator ?? new DefaultActivator(); CompilerServiceFactory = xmlConfig.CompilerServiceFactory ?? new DefaultCompilerServiceFactory(); EncodedStringFactory = xmlConfig.EncodedStringFactory ?? new HtmlEncodedStringFactory(); CodeInspectors = xmlConfig.CodeInspectors != null?xmlConfig.CodeInspectors.ToList() : new List <ICodeInspector>(); Language = xmlConfig.Language; Namespaces = new HashSet <string> { "System", "System.Collections.Generic", "System.Linq" }; Namespaces.UnionWith(xmlConfig.Namespaces); }