/// <summary> /// Creates an instance of a <see cref="TemplateService"/>. /// </summary> /// <param name="configuration">The <see cref="TemplateServiceConfigurationElement"/> that represents the configuration.</param> /// <param name="defaultNamespaces">The enumerable of namespaces to add as default.</param> /// <returns>A new instance of <see cref="TemplateService"/>.</returns> public static TemplateService CreateTemplateService(TemplateServiceConfigurationElement configuration, IEnumerable<string> defaultNamespaces = null) { if (configuration == null) throw new ArgumentNullException("configuration"); ILanguageProvider provider = null; MarkupParser parser = null; Type templateBaseType = null; if (!string.IsNullOrEmpty(configuration.LanguageProvider)) provider = (ILanguageProvider)GetInstance(configuration.LanguageProvider); if (!string.IsNullOrEmpty(configuration.MarkupParser)) parser = (MarkupParser)GetInstance(configuration.MarkupParser); if (!string.IsNullOrEmpty(configuration.TemplateBase)) templateBaseType = GetType(configuration.TemplateBase); var namespaces = configuration.Namespaces .Cast<NamespaceConfigurationElement>() .Select(n => n.Namespace); if (defaultNamespaces != null) { namespaces = defaultNamespaces .Concat(namespaces) .Distinct(); } var service = new TemplateService(provider, templateBaseType, parser); foreach (string ns in namespaces) service.Namespaces.Add(ns); return service; }
/// <summary> /// Creates an instance of a template service from configuration. /// </summary> /// <param name="config">The configuration of the template service.</param> /// <returns>An instance of <see cref="TemplateService"/>.</returns> public static TemplateService CreateTemplateService(TemplateServiceConfigurationElement config) { if (config == null) throw new ArgumentNullException("config"); MarkupParser parser = null; if (!string.IsNullOrWhiteSpace(config.MarkupParser)) parser = CreateMarkupParser(config.MarkupParser); return CreateTemplateService(config.Language, config.StrictMode, parser); }
/// <summary> /// Creates an instance of a template service from configuration. /// </summary> /// <param name="config">The configuration of the template service.</param> /// <returns>An instance of <see cref="TemplateService"/>.</returns> public static TemplateService CreateTemplateService(TemplateServiceConfigurationElement config) { if (config == null) { throw new ArgumentNullException("config"); } MarkupParser parser = null; if (!string.IsNullOrWhiteSpace(config.MarkupParser)) { parser = CreateMarkupParser(config.MarkupParser); } return(CreateTemplateService(config.Language, config.StrictMode, parser)); }
/// <summary> /// Creates an instance of a <see cref="TemplateService"/>. /// </summary> /// <param name="configuration">The <see cref="TemplateServiceConfigurationElement"/> that represents the configuration.</param> /// <param name="defaultNamespaces">The enumerable of namespaces to add as default.</param> /// <returns>A new instance of <see cref="TemplateService"/>.</returns> public static TemplateService CreateTemplateService(TemplateServiceConfigurationElement configuration, IEnumerable <string> defaultNamespaces = null) { if (configuration == null) { throw new ArgumentNullException("configuration"); } ILanguageProvider provider = null; MarkupParser parser = null; Type templateBaseType = null; if (!string.IsNullOrEmpty(configuration.LanguageProvider)) { provider = (ILanguageProvider)GetInstance(configuration.LanguageProvider); } if (!string.IsNullOrEmpty(configuration.MarkupParser)) { parser = (MarkupParser)GetInstance(configuration.MarkupParser); } if (!string.IsNullOrEmpty(configuration.TemplateBase)) { templateBaseType = GetType(configuration.TemplateBase); } var namespaces = configuration.Namespaces .Cast <NamespaceConfigurationElement>() .Select(n => n.Namespace); if (defaultNamespaces != null) { namespaces = defaultNamespaces .Concat(namespaces) .Distinct(); } var service = new TemplateService(provider, templateBaseType, parser); foreach (string ns in namespaces) { service.Namespaces.Add(ns); } return(service); }