Пример #1
0
        private static void Cache <T>(MethodInfo self, Type type, T instance) where T : Attribute
        {
            ConcurrentDictionary <Type, Attribute> root;

            if (!MethodReflectionCache.TryGetValue(self, out root))
            {
                root = new ConcurrentDictionary <Type, Attribute>();
                MethodReflectionCache.TryAdd(self, root);
            }
            if (!root.ContainsKey(type))
            {
                root.TryAdd(type, instance);
            }
        }
Пример #2
0
        private static T LookupInCache <T>(MethodInfo self, Type type, out bool hasItem) where T : Attribute
        {
            ConcurrentDictionary <Type, Attribute> root;

            if (MethodReflectionCache.TryGetValue(self, out root))
            {
                Attribute leaf;
                if (root.TryGetValue(type, out leaf))
                {
                    hasItem = true;
                    return((T)leaf);
                }
            }
            hasItem = false;
            return(default(T));
        }