/// <summary> /// Merges two config sets into one and throws an exception if there are any conflicts. /// </summary> /// <param name="source">The source config set to user.</param> public void Merge(IConfigSet source) { // Merges between different types don't yield anything if (this.GetType() == source.GetType()) { this.MergeThrowOnConflicts(source); } }
/// <summary> /// Merges two config sets into one. /// </summary> /// <param name="source">The source config set to user.</param> /// <param name="mergeRule">The merge rule to use.</param> public void Merge(IConfigSet source, MergeRules mergeRule) { // Merges between different types don't yield anything if (this.GetType() != source.GetType()) { return; } if (mergeRule == MergeRules.ThrowOnConflicts) { this.MergeThrowOnConflicts(source); return; } foreach (var kvp in source) { object currValue; if (this.TryGetValue(kvp.Key, out currValue)) { if (!currValue.Equals(kvp.Value)) { switch (mergeRule) { case MergeRules.Overwrite: this.SetParam(kvp.Key, kvp.Value); break; case MergeRules.KeepExisting: break; default: throw new ArgumentException("Unsupported merge rule!", "mergeRule"); } } } else { this.SetParam(kvp.Key, kvp.Value); } } }