Here are the examples of the csharp api System.Collections.Generic.IDictionary.ContainsKey(K) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
32 Examples
19
Source : EnumerableExtensions.cs
with GNU General Public License v3.0
from deepak-rathi
with GNU General Public License v3.0
from deepak-rathi
public static bool TryAdd<K, V>(this IDictionary<K, V> dictionary, K key, V value)
{
if (dictionary.ContainsKey(key))
{
return false;
}
else
{
try
{
dictionary.Add(key, value);
return true;
}
catch
{
return false;
}
}
}
19
Source : DictionaryHelper.cs
with GNU Lesser General Public License v3.0
from dotnettools
with GNU Lesser General Public License v3.0
from dotnettools
public static V GetOrDefault<K, V>(this IDictionary<K, V> dictionary, K key, V defaultValue = default)
{
if (!dictionary.ContainsKey(key))
return defaultValue;
return dictionary[key];
}
19
Source : AssertEx.cs
with Apache License 2.0
from endink
with Apache License 2.0
from endink
public static void Equals<K, V>(IDictionary<K, V> d1, IDictionary<K, V> d2)
{
replacedert.NotNull(d1);
replacedert.NotNull(d2);
replacedert.Equal(d1.Count, d2.Count);
foreach (var kp in d1)
{
replacedert.True(d2.ContainsKey(kp.Key), $"expected key was not found: {kp.Key}");
replacedert.Equal(kp.Value, d2[kp.Key]);
}
}
19
Source : ReadOnlyConvertingDictionary.cs
with MIT License
from enricosada
with MIT License
from enricosada
public bool ContainsKey(K key)
{
return _backing.ContainsKey(key);
}
19
Source : HybridDictionary_Tests.cs
with MIT License
from enricosada
with MIT License
from enricosada
private void replacedertDictionariesIdentical<K, V>(IDictionary<K, V> one, IDictionary<K, V> two)
{
replacedert.Equal(one.Count, two.Count); // "Counts are unequal, {0} and {1}", one.Count, two.Count
foreach (KeyValuePair<K, V> entry in one)
{
V value;
if (!two.TryGetValue(entry.Key, out value))
{
replacedert.True(false, string.Format("one had key {0} the other didn't", entry.Key));
}
if (!value.Equals(entry.Value))
{
replacedert.True(false, string.Format("one had {0}={1} the other {2}={3}", entry.Key, entry.Value, entry.Key, value));
}
}
foreach (var key in one.Keys)
{
replacedert.Equal(true, two.ContainsKey(key));
}
var oneValues = new List<V>(one.Values);
var twoValues = new List<V>(two.Values);
oneValues.Sort();
twoValues.Sort();
replacedert.Equal(oneValues.Count, twoValues.Count); //"Value counts are unequal, {0} and {1}", oneValues.Count, twoValues.Count
for (int i = 0; i < oneValues.Count; i++)
{
replacedert.Equal(oneValues[i], twoValues[i]);
}
// Now repeat, using IDictionary interface
IDictionary oneId = (IDictionary)one;
IDictionary twoId = (IDictionary)two;
replacedert.Equal(oneId.Count, twoId.Count); // "Counts are unequal, {0} and {1}", oneId.Count, twoId.Count
foreach (DictionaryEntry entry in oneId)
{
if (!twoId.Contains(entry.Key))
{
replacedert.True(false, string.Format("oneId had key {0} the other didn't", entry.Key));
}
if (!entry.Value.Equals(twoId[entry.Key]))
{
replacedert.True(false, string.Format("oneId had {0}={1} the other {2}={3}", entry.Key, entry.Value, entry.Key, twoId[entry.Key]));
}
}
foreach (var key in oneId.Keys)
{
replacedert.Equal(true, twoId.Contains(key));
}
var oneIdValues = new ArrayList(oneId.Values);
var twoIdValues = new ArrayList(twoId.Values);
oneIdValues.Sort();
twoIdValues.Sort();
replacedert.Equal(oneIdValues.Count, twoIdValues.Count); // "Value counts are unequal, {0} and {1}", oneIdValues.Count, twoIdValues.Count
for (int i = 0; i < oneIdValues.Count; i++)
{
replacedert.Equal(oneIdValues[i], twoIdValues[i]);
}
}
19
Source : ReadOnlyEmptyDictionary.cs
with MIT License
from enricosada
with MIT License
from enricosada
public bool Contains(object key)
{
return ((IDictionary<K, V>)this).ContainsKey((K)key);
}
19
Source : TarsInputStream.cs
with BSD 3-Clause "New" or "Revised" License
from fs7744
with BSD 3-Clause "New" or "Revised" License
from fs7744
public IDictionary<K, V> ReadMap<K, V>(IDictionary<K, V> m, int tag, bool isRequire)
{
if (m == null)
{
return null;
}
var mk = default(K);
var mv = default(V);
if (SkipToTag(tag))
{
HeadData hd = new HeadData();
ReadHead(hd);
switch (hd.Type)
{
case (byte)TarsStructType.Map:
{
int size = Read(0, 0, true);
if (size < 0)
{
throw new TarsDecodeException("size invalid: " + size);
}
for (int i = 0; i < size; ++i)
{
mk = (K)Read(mk, 0, true);
mv = (V)Read(mv, 1, true);
if (mk != null)
{
if (m.ContainsKey(mk))
{
m[mk] = mv;
}
else
{
m.Add(mk, mv);
}
}
}
}
break;
default:
{
throw new TarsDecodeException("type mismatch.");
}
}
}
else if (isRequire)
{
throw new TarsDecodeException("require field not exist.");
}
return m;
}
19
Source : IEnumerableExtensions.cs
with MIT License
from LanceMcCarthy
with MIT License
from LanceMcCarthy
public static bool TryAdd<K, V>(this IDictionary<K, V> dictionary, K key, V value)
{
if (dictionary.ContainsKey(key))
{
return false;
}
try
{
dictionary.Add(key, value);
return true;
}
catch
{
return false;
}
}
19
Source : DictionaryExtensions.cs
with MIT License
from LGouellec
with MIT License
from LGouellec
public static bool AddOrUpdate<K, V>(this IDictionary<K, V> map, K key, V value)
{
if (map.ContainsKey(key))
{
map[key] = value;
return false;
}
else
{
map.Add(key, value);
return true;
}
}
19
Source : LinqExtensions.cs
with MIT License
from LGouellec
with MIT License
from LGouellec
internal static V Get<K,V>(this IDictionary<K,V> map, K key)
{
if (map.ContainsKey(key))
return map[key];
else
return default(V);
}
19
Source : Collections.cs
with MIT License
from LunariStudios
with MIT License
from LunariStudios
public static V GetOrPut<K, V>(this IDictionary<K, V> collection, K key, Func<V> instantiator) {
if (collection.ContainsKey(key)) {
return collection[key];
}
var newObj = instantiator();
collection[key] = newObj;
return newObj;
}
19
Source : IDictionary.net5.cs
with MIT License
from microsoft
with MIT License
from microsoft
public bool Contains(K item)
{
return dictionary.ContainsKey(item);
}
19
Source : IDictionary.net5.cs
with MIT License
from microsoft
with MIT License
from microsoft
public bool HasKey(K key) => _dictionary.ContainsKey(key);
19
Source : IDictionary.net5.cs
with MIT License
from microsoft
with MIT License
from microsoft
public bool Insert(K key, V value)
{
bool replacing = _dictionary.ContainsKey(key);
_dictionary[key] = value;
return replacing;
}
19
Source : StrictDictionary.cs
with MIT License
from microsoft
with MIT License
from microsoft
public bool ContainsKey(K key)
{
return _backingDictionary.ContainsKey(key);
}
19
Source : DefaultKeyedVariables.cs
with MIT License
from openrpg
with MIT License
from openrpg
public bool ContainsKey(K key) => InternalVariables.ContainsKey(key);
19
Source : DictionaryByValue.cs
with MIT License
from osoykan
with MIT License
from osoykan
public bool ContainsKey(K key) => dictionary.ContainsKey(key);
19
Source : CollectionAssert.cs
with MIT License
from pelikhan
with MIT License
from pelikhan
public static void DoesNotContainKey<K, V>(IDictionary<K, V> dictionary, K value)
{
replacedert.IsFalse(dictionary.ContainsKey(value),
"Collection contains {0}", value);
}
19
Source : CollectionAssert.cs
with MIT License
from pelikhan
with MIT License
from pelikhan
public static void ContainsKey<K, V>(IDictionary<K, V> dictionary, K value)
{
replacedert.IsTrue(dictionary.ContainsKey(value),
"Collection does not contain {0}", value);
}
19
Source : ExtensionMethods.cs
with MIT License
from phantasma-io
with MIT License
from phantasma-io
public static void Merge<K, V>(this IDictionary<K, V> target, IDictionary<K, V> source)
{
source.ToList().ForEach(_ => {
if (!target.ContainsKey(_.Key))
{
target[_.Key] = _.Value;
}
});
}
19
Source : EngineIntegrationTests.Registry.cs
with MIT License
from reaqtive
with MIT License
from reaqtive
public bool ContainsKey(K key) => _dictionary.ContainsKey(key);
19
Source : CustomCollections.cs
with MIT License
from redscientistlabs
with MIT License
from redscientistlabs
public bool ContainsKey(K key) { return dictionary.ContainsKey(key); }
19
Source : ThreadSafeDictionary.cs
with GNU General Public License v3.0
from Roxeez
with GNU General Public License v3.0
from Roxeez
public bool ContainsKey(K key)
{
lock (_lock)
{
return _internalDictionary.ContainsKey(key);
}
}
19
Source : GeneralExtensions.cs
with MIT License
from samfundev
with MIT License
from samfundev
public static void AddSafe<K, V>(this IDictionary<K, List<V>> dic, K key, V value)
{
if (dic == null)
throw new ArgumentNullException(nameof(dic));
if (key == null)
throw new ArgumentNullException(nameof(key), "Null values cannot be used for keys in dictionaries.");
if (!dic.ContainsKey(key))
dic[key] = new List<V>();
dic[key].Add(value);
}
19
Source : RadiacUtility.cs
with GNU General Public License v3.0
from State-of-War-PostBar
with GNU General Public License v3.0
from State-of-War-PostBar
public static V ElementAt<K, V>(this IDictionary<K, V> dict, K index)
where V : new()
{
if(dict.ContainsKey(index)) return dict[index];
V newElement = new V();
dict.Add(index, newElement);
return newElement;
}
19
Source : IDictionaryGeneric{`2}Extensions.cs
with MIT License
from teroneko
with MIT License
from teroneko
public static V AddOrUpdate<K, V>(this IDictionary<K, V> dictionary, K key, V value)
where K : notnull
{
if (!dictionary.ContainsKey(key)) {
return dictionary.AddAndReturn(key, value);
} else {
return dictionary[key] = value;
}
}
19
Source : Util.cs
with Apache License 2.0
from thefifthmatt
with Apache License 2.0
from thefifthmatt
public static void AddMulti<K, V>(IDictionary<K, List<V>> dict, K key, V value)
{
if (!dict.ContainsKey(key)) dict[key] = new List<V>();
dict[key].Add(value);
}
19
Source : Util.cs
with Apache License 2.0
from thefifthmatt
with Apache License 2.0
from thefifthmatt
public static void AddMulti<K, V, U>(IDictionary<K, Dictionary<V, U>> dict, K key, V value, U value2)
{
if (!dict.ContainsKey(key)) dict[key] = new Dictionary<V, U>();
dict[key][value] = value2;
}
19
Source : Util.cs
with Apache License 2.0
from thefifthmatt
with Apache License 2.0
from thefifthmatt
public static void AddMulti<K, V>(IDictionary<K, List<V>> dict, K key, IEnumerable<V> values)
{
if (!dict.ContainsKey(key)) dict[key] = new List<V>();
dict[key].AddRange(values);
}
19
Source : Util.cs
with Apache License 2.0
from thefifthmatt
with Apache License 2.0
from thefifthmatt
public static void AddMulti<K, V>(IDictionary<K, HashSet<V>> dict, K key, V value)
{
if (!dict.ContainsKey(key)) dict[key] = new HashSet<V>();
dict[key].Add(value);
}
19
Source : Util.cs
with Apache License 2.0
from thefifthmatt
with Apache License 2.0
from thefifthmatt
public static void AddMulti<K, V>(IDictionary<K, HashSet<V>> dict, K key, IEnumerable<V> values)
{
if (!dict.ContainsKey(key)) dict[key] = new HashSet<V>();
dict[key].UnionWith(values);
}
19
Source : Util.cs
with Apache License 2.0
from thefifthmatt
with Apache License 2.0
from thefifthmatt
public static void AddMulti<K, V>(IDictionary<K, SortedSet<V>> dict, K key, V value)
{
if (!dict.ContainsKey(key)) dict[key] = new SortedSet<V>();
dict[key].Add(value);
}