public V this[K key] { get { int hashKey = key.GetHashCode(); List <Pair> list = DictionaryExtension.ValueOrDefault(dic, hashKey); if (list == null) { return(default(V)); } for (int a = list.Count; a-- > 0;) { Pair p = list[a]; Object target = p.Key.Target; if (target == null) { continue; } if (AreKeysEqual((K)target, key)) { return((V)p.Value); } } return(default(V)); } set { Add(key, value); } }
public void Add(K key, V value) { int hashKey = key.GetHashCode(); List <Pair> list = DictionaryExtension.ValueOrDefault(dic, hashKey); if (list == null) { list = new List <Pair>(2); dic.Add(hashKey, list); } for (int a = list.Count; a-- > 0;) { Pair p = list[a]; Object target = p.Key.Target; if (target == null) { removeItemFromList(hashKey, list, p, a); continue; } if (AreKeysEqual((K)target, key)) { p.Value = value; return; } } Pair newP = new Pair(); newP.Key = new WeakReference(key); newP.Value = value; list.Add(newP); count++; }
internal bool IsCounted(Dictionary <Thread, int> threadToCountDict) { Thread thread = Thread.CurrentThread; int counter = DictionaryExtension.ValueOrDefault(threadToCountDict, thread); return(counter > 0); }
public bool Remove(K key) { int hashKey = key.GetHashCode(); List <Pair> list = DictionaryExtension.ValueOrDefault(dic, hashKey); if (list == null) { return(false); } for (int a = list.Count; a-- > 0;) { Pair p = list[a]; Object target = p.Key.Target; if (target == null) { removeItemFromList(hashKey, list, p, a); continue; } if (AreKeysEqual((K)target, key)) { removeItemFromList(hashKey, list, p, a); return(true); } } return(false); }
public static bool IsGenericList(Type type) { if (!type.IsGenericType) { return(false); } IDictionary <Type, bool?> typeToGenericCollectionDict = typeToGenericCollectionDictTL.Value; bool?result = DictionaryExtension.ValueOrDefault(typeToGenericCollectionDict, type); if (result == null) { result = false; Type[] typeInterfaces = type.GetInterfaces(); foreach (Type typeInterface in typeInterfaces) { if (!typeInterface.IsGenericType) { continue; } Type genericType = typeInterface.GetGenericTypeDefinition(); result = typeof(IList <>).IsAssignableFrom(genericType); break; } typeToGenericCollectionDict.Add(type, result); } return(result.Value); }
internal void IncrementCounter(Dictionary <Thread, int> threadToCountDict) { Thread thread = Thread.CurrentThread; int counter = DictionaryExtension.ValueOrDefault(threadToCountDict, thread); counter++; threadToCountDict[thread] = counter; }
public bool Remove(KeyValuePair <K, V> item) { V value = DictionaryExtension.ValueOrDefault(this, item.Key); if (Object.Equals(value, item.Value)) { Remove(item.Key); return(true); } return(false); }
public static IList <TValue> GetList <TKey, TValue>(IDictionary <TKey, IList <TValue> > dictionary, TKey key) { IList <TValue> list = DictionaryExtension.ValueOrDefault(dictionary, key); if (list == null) { list = new List <TValue>(); dictionary.Add(key, list); } return(list); }
internal void DecrementCounter(Dictionary <Thread, int> threadToCountDict) { Thread thread = Thread.CurrentThread; int counter = DictionaryExtension.ValueOrDefault(threadToCountDict, thread); counter--; if (counter > 0) { threadToCountDict[thread] = counter; } else { threadToCountDict.Remove(thread); } }
public static Type GetTypeFromAssemblies(String typeName) { IDictionary <String, Type> nameToTypeDict = nameToTypeDictTL.Value; Type type = DictionaryExtension.ValueOrDefault(nameToTypeDict, typeName); if (type != null) { return(type); } if (nameToTypeDict.ContainsKey(typeName)) { return(null); } type = Type.GetType(typeName); if (type != null) { nameToTypeDict.Add(typeName, type); return(type); } lock (Assemblies) { foreach (Assembly assembly in Assemblies) { type = assembly.GetType(typeName, false); if (type != null) { nameToTypeDict.Add(typeName, type); return(type); } } } // GN: If we add to the nameToTypeDict here, we have the problem, that we return in line 141 the next time, even if the type is available by that time. // Concrete example: ValueObjectConfigReader handles the configuration of "ProcessingRequest" from the delivery domain. This entity has a relation to // "ProcessingStepType" from the processing domain, hence the ValueObjectConfigReader calls this method to determine the VO type. As we are in a warehouse // screen that needs no procesing entities, the type cannot be found. Now we switch to another warehouse screen that has dependencies to processing, but we // return in line 141, although the assembly is now available. //nameToTypeDict.Add(typeName, null); return(null); }
public WeakReference GetWeakReferenceEntry(K key) { int hashKey = key.GetHashCode(); List <Pair> list = DictionaryExtension.ValueOrDefault(dic, hashKey); if (list == null) { return(null); } for (int a = list.Count; a-- > 0;) { Pair p = list[a]; Object target = p.Key.Target; if (target == null) { continue; } if (AreKeysEqual((K)target, key)) { return(p.Key); } } return(null); }
public bool Contains(KeyValuePair <K, V> item) { V value = DictionaryExtension.ValueOrDefault(this, item.Key); return(Object.Equals(value, item.Value)); }
public static Type GetTypeFromCurrentDomain(String typeName) { return(DictionaryExtension.ValueOrDefault(nameToTypeDict, typeName)); }