private void LoadSections() { SectionList loadedSections = _loader.Load(); CheckForPresenseOfGlobalSection(loadedSections); _sections.AddRange(loadedSections); }
private static void CheckForPresenseOfGlobalSection(SectionList loadedSections) { if (loadedSections == null || loadedSections.Count == 0 || !loadedSections [0].IsGlobal) { throw new ConfigurationException( "The loaded sections should contain at least one section. The first section should be named 'Global'"); } }
/// <summary> /// Initializes a new instance of the ConfigurationHandler class. /// </summary> /// <param name="loader"></param> public ConfigurationHandler(IConfigurationLoader loader, SectionList predefinedSections, List <ISettingParser> settingParsers, List <ISettingsProcessor> processors) { _loader = loader; _predefinedSections.AddRange(predefinedSections); RegisterParsers(settingParsers); RegisterProcessors(processors); RegisterForLoaderSettingsChanged(); }
//Helper methods public static IConfigurationHandler CreateConfig(Dictionary <string, object> settings) { Section globalSection = new Section("Global"); foreach (KeyValuePair <string, object> pair in settings) { globalSection.Add(Setting.CreateProcessedSetting(pair.Key, pair.Value)); } var sections = new SectionList() { globalSection }; ConfigurationHandler config = new ConfigurationHandler(new SettingsConfigurationLoader(globalSection)); config.LoadSettings(); return(config); }
/// <summary> /// Initializes a new instance of the ConfigurationHandler class. /// </summary> /// <param name="loader"></param> public ConfigurationHandler(IConfigurationLoader loader, SectionList predefinedSections) : this(loader, predefinedSections, new List <ISettingParser> (), new List <ISettingsProcessor> ()) { }