コード例 #1
0
        public void AddIfNotContainsKeyTest2NullCheck()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => IDictionaryEx.AddIfNotContainsKey(null, new Object(), () => new Object());

            Assert.Throws <ArgumentNullException>(test);
        }
コード例 #2
0
        public void AddOrUpdateTest1NullCheck()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => IDictionaryEx.AddOrUpdate(null, new KeyValuePair <Object, Object>(new Object(), new Object()));

            Assert.Throws <ArgumentNullException>(test);
        }
コード例 #3
0
        public void AddIfNotContainsKey1TestNullCheck1()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => IDictionaryEx.AddIfNotContainsKey(null, new KeyValuePair <Object, Object>());

            Assert.Throws <ArgumentNullException>(test);
        }
コード例 #4
0
        public void AddOrUpdateTest2NullCheck()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => IDictionaryEx.AddOrUpdate(null, new Object(), () => new Object());

            test.ShouldThrow <ArgumentNullException>();
        }
コード例 #5
0
        public void AddRangeTestNullCheck()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => IDictionaryEx.AddRange(null, new Dictionary <Object, Object>());

            test.ShouldThrow <ArgumentNullException>();
        }
コード例 #6
0
        public void AddIfNotContainsKeyTestNullCheck()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => IDictionaryEx.AddIfNotContainsKey(null, new Object(), new Object());

            test.ShouldThrow <ArgumentNullException>();
        }
コード例 #7
0
        public void GetOrAddCaseNullCheck()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            // ReSharper disable once MustUseReturnValue
            Action test = () => IDictionaryEx.GetOrAdd(null, new Object(), new Object());

            Assert.Throws <ArgumentNullException>(test);
        }
コード例 #8
0
        public void GetOrAddCase1NullCheck()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            // ReSharper disable once MustUseReturnValue
            Action test = () => IDictionaryEx.GetOrAdd(null, new KeyValuePair <Object, Object>(new Object(), new Object()));

            test.ShouldThrow <ArgumentNullException>();
        }
コード例 #9
0
ファイル: IDictionaryEx.cs プロジェクト: dadhi/ecsharp
 /// <summary>Adds a new key/value pair if the key was not present, or gets the existing
 /// value if the key was present.</summary>
 /// <returns>The existing value. If a new pair was added, the result has no value.</returns>
 /// <seealso cref="GetOrAdd{K, V}(IDictionaryEx{K, V}, K, V)"/>
 public static Maybe <V> AddOrGetExisting <K, V>(this IDictionaryEx <K, V> dict, K key, V value)
 {
     if (dict.GetAndEdit(ref key, ref value, DictEditMode.AddIfNotPresent))
     {
         return(value);
     }
     return(default(Maybe <V>));
 }
コード例 #10
0
ファイル: IDictionaryEx.cs プロジェクト: dadhi/ecsharp
 /// <summary>Associates a key with a value in the dictionary, and gets the old value
 /// if the key was already present.</summary>
 /// <returns>The old value associated with the same key. If a new pair was added,
 /// the result has no value.</returns>
 public static Maybe <V> GetAndSet <K, V>(this IDictionaryEx <K, V> dict, K key, V value)
 {
     if (dict.GetAndEdit(ref key, ref value, DictEditMode.AddOrReplace))
     {
         return(value);
     }
     return(new Maybe <V>());
 }
コード例 #11
0
ファイル: IDictionaryEx.cs プロジェクト: dadhi/ecsharp
 public static Maybe <V> SetAndGet <K, V>(this IDictionaryEx <K, V> dict, K key, V value) => GetAndSet(dict, key, value);
コード例 #12
0
ファイル: IDictionaryEx.cs プロジェクト: dadhi/ecsharp
 /// <summary>Replaces an item in the map if the key was already present.
 /// If the key was not already present, this method has no effect.</summary>
 /// <returns>The old value if a value was replaced, or an empty value of <see cref="Maybe{V}"/> otherwise.</returns>
 public static Maybe <V> SwapIfPresent <K, V>(this IDictionaryEx <K, V> dict, K key, V value)
 {
     return(dict.GetAndEdit(ref key, ref value, DictEditMode.ReplaceIfPresent) ?
            (Maybe <V>)value : default(Maybe <V>));
 }
コード例 #13
0
ファイル: IDictionaryEx.cs プロジェクト: dadhi/ecsharp
 /// <summary>Replaces an item in the map if the key was already present.
 /// If the key was not already present, this method has no effect.</summary>
 /// <returns>True if a value existed and was replaced, false if not.</returns>
 public static bool ReplaceIfPresent <K, V>(this IDictionaryEx <K, V> dict, K key, V value)
 {
     return(dict.GetAndEdit(ref key, ref value, DictEditMode.ReplaceIfPresent));
 }
コード例 #14
0
ファイル: IDictionaryEx.cs プロジェクト: dadhi/ecsharp
 /// <summary>Adds a key/value pair to the dictionary if the key is not already present,
 /// and returns the existing or new value.</summary>
 /// <returns>The existing value (if the key already existed) or the new value.</returns>
 public static V GetOrAdd <K, V>(this IDictionaryEx <K, V> dict, K key, V value)
 {
     dict.GetAndEdit(ref key, ref value, DictEditMode.AddIfNotPresent);
     return(value);
 }
コード例 #15
0
ファイル: IDictionaryEx.cs プロジェクト: dadhi/ecsharp
 public static bool TryAdd <K, V>(this IDictionaryEx <K, V> dict, K key, V value)
 {
     return(!dict.GetAndEdit(ref key, ref value, DictEditMode.AddIfNotPresent));
 }