/// <summary> /// Add a path formed by the nodes of the nested switches with the value associated /// </summary> /// <param name="keys">path of case statements from the nested switches</param> /// <param name="value">associated value</param> /// <param name="replace">replace the value if the path already exists</param> public void Add(IEnumerable <TKey> keys, TValue value, bool replace = true) { if (_index - keys.Count() >= 0) { if (replace) { Value = value; } } else { TKey key = keys.ElementAt(_index); NestedSwitchesBuilder <TKey, TValue> child; if (!_children.TryGetValue(key, out child)) { child = new NestedSwitchesBuilder <TKey, TValue>(this, _index + 1) { Key = key }; _children.Add(key, child); } child.Add(keys, value, replace); } }
private NestedSwitchesBuilder(NestedSwitchesBuilder <TKey, TValue> parent, int index) { _parent = parent; _children = new Dictionary <TKey, NestedSwitchesBuilder <TKey, TValue> >(); _index = index; }