/// <summary> /// Create a child settings composer with the given parent /// </summary> /// <param name="parent"></param> public SettingsComposer(SettingsComposer parent) { if (parent == null) { XmlConverter = new SettingsXmlConverter(); return; } XmlConverter = parent.XmlConverter; Parent = parent; }
/// <summary> /// Update the settings using the given source. If the ignoreChain flag is true /// (the default), this composer is updated without regard to the contents of its /// parents. If the ignoreChain is false, only items not present in the chain /// (meaning both key and value per item) are modified in this composer. /// </summary> /// <param name="source"></param> /// <param name="ignoreChain"></param> /// <returns></returns> public SettingsComposer UpdateFrom(SettingsComposer source, bool ignoreChain = true) { var newSource = ignoreChain ? source : source.Where(item => ChainContains(item.Key, item.Value) == false); foreach (var item in newSource) { this[item.Key] = item.Value; } return(this); }
/// <summary> /// Reads all settings of this composer and its parents into a single composer /// If a key is present in a parent and child, the item of the child is returned and /// the parent's item is discarded /// </summary> /// <returns></returns> public SettingsComposer ReadAllSettings() { var result = new SettingsComposer(); for (var composer = this; composer != null; composer = composer.Parent) { foreach (var item in composer.Where(item => result._settingsDictionary.ContainsKey(item.Key) == false)) { result._settingsDictionary.Add(item.Key, item.Value); } } return(result); }