public OptionsStorage(ISettingsService settingsService) { if (settingsService == null) { throw new ArgumentNullException(nameof(settingsService)); } toGroupSection = new Dictionary <string, ISettingsSection>(StringComparer.Ordinal); toSubGroupSection = new Dictionary <SubGroupKey, ISettingsSection>(); toOptionSection = new Dictionary <OptionKey, ISettingsSection>(); settingsSection = settingsService.GetOrCreateSection(SETTINGS_GUID); foreach (var groupSect in settingsSection.SectionsWithName(GroupName)) { var groupName = groupSect.Attribute <string>(GroupNameAttr); if (groupName == null) { continue; } if (toGroupSection.ContainsKey(groupName)) { continue; } toGroupSection[groupName] = groupSect; foreach (var ctSect in groupSect.SectionsWithName(SubGroupName)) { var subGroup = ctSect.Attribute <string>(SubGroupNameAttr); if (subGroup == null) { continue; } var key = new SubGroupKey(groupName, subGroup); if (toSubGroupSection.ContainsKey(key)) { continue; } toSubGroupSection[key] = ctSect; foreach (var optSect in ctSect.SectionsWithName(OptionName)) { var name = optSect.Attribute <string>(OptionNameAttr); if (name == null) { continue; } var optKey = new OptionKey(key, name); if (toOptionSection.ContainsKey(optKey)) { continue; } toOptionSection[optKey] = optSect; } } } }
ISettingsSection GetOrCreateSubGroupSection(string groupName, string subGroup) { var key = new SubGroupKey(groupName, subGroup); if (toSubGroupSection.TryGetValue(key, out var sect)) { return(sect); } var groupSect = GetOrCreateGroupSection(groupName); sect = groupSect.CreateSection(SubGroupName); toSubGroupSection.Add(key, sect); sect.Attribute(SubGroupNameAttr, subGroup); return(sect); }
public OptionKey(SubGroupKey subGroupKey, string name) { this.subGroupKey = subGroupKey; this.name = name; }