コード例 #1
0
ファイル: WeakDictionary.cs プロジェクト: vogelb/ambeth
 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);
     }
 }
コード例 #2
0
ファイル: WeakDictionary.cs プロジェクト: vogelb/ambeth
        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++;
        }
コード例 #3
0
ファイル: ReadWriteLock.cs プロジェクト: vogelb/ambeth
        internal bool IsCounted(Dictionary <Thread, int> threadToCountDict)
        {
            Thread thread  = Thread.CurrentThread;
            int    counter = DictionaryExtension.ValueOrDefault(threadToCountDict, thread);

            return(counter > 0);
        }
コード例 #4
0
ファイル: WeakDictionary.cs プロジェクト: vogelb/ambeth
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: ReadWriteLock.cs プロジェクト: vogelb/ambeth
        internal void IncrementCounter(Dictionary <Thread, int> threadToCountDict)
        {
            Thread thread  = Thread.CurrentThread;
            int    counter = DictionaryExtension.ValueOrDefault(threadToCountDict, thread);

            counter++;
            threadToCountDict[thread] = counter;
        }
コード例 #7
0
ファイル: WeakDictionary.cs プロジェクト: vogelb/ambeth
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: ReadWriteLock.cs プロジェクト: vogelb/ambeth
        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);
            }
        }
コード例 #10
0
ファイル: AssemblyHelper.cs プロジェクト: vogelb/ambeth
        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);
        }
コード例 #11
0
ファイル: WeakDictionary.cs プロジェクト: vogelb/ambeth
        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);
        }
コード例 #12
0
ファイル: WeakDictionary.cs プロジェクト: vogelb/ambeth
        public bool Contains(KeyValuePair <K, V> item)
        {
            V value = DictionaryExtension.ValueOrDefault(this, item.Key);

            return(Object.Equals(value, item.Value));
        }
コード例 #13
0
ファイル: AssemblyHelper.cs プロジェクト: vogelb/ambeth
 public static Type GetTypeFromCurrentDomain(String typeName)
 {
     return(DictionaryExtension.ValueOrDefault(nameToTypeDict, typeName));
 }