internal static FluentDictionary <TKey, TValue> AddOrUpdate <TKey, TValue>(this FluentDictionary <TKey, TValue> dictionary, TKey key, TValue value, Predicate <TValue> predicate = null)
 {
     if (predicate?.Invoke(value) ?? true)
     {
         if (dictionary.ContainsKey(key))
         {
             dictionary[key] = value;
         }
         dictionary.Add(key, value);
     }
     return(dictionary);
 }
Exemple #2
0
        public void GenericTools_Collections_FluentDictionary()
        {
            var dict = new FluentDictionary <string, int>()
                       .Add("Key1", 1)
                       .Add("Key2", 2)
                       .Add("Key3", 3)
                       .Remove("Key3");

            MakeSure.That(dict.Count).Is(2);
            MakeSure.That(dict.ContainsKey("Key2")).Is(true);
            MakeSure.That(dict["Key1"]).Is(1);
            MakeSure.That(dict.Keys.Count).Is(2);
            MakeSure.That(dict.Values.Count).Is(2);

            dict.Clear();

            MakeSure.That(dict.Count).Is(0);
        }
Exemple #3
0
 protected virtual bool CanContribute(KeyValuePair <string, T> setting, FluentDictionary <string, T> existing)
 {
     return(!existing.ContainsKey(setting.Key));
 }