コード例 #1
0
 private static void Cache <T>(Type self, Type type, T instance) where T : Attribute
 {
     if (!TypeReflectionCache.ContainsKey(self))
     {
         TypeReflectionCache.TryAdd(self, new ConcurrentDictionary <Type, Attribute>());
     }
     if (!TypeReflectionCache[self].ContainsKey(type))
     {
         TypeReflectionCache[self].TryAdd(type, instance);
     }
 }
コード例 #2
0
        private static T LookupInCache <T>(Type self, Type type, out bool hasItem) where T : Attribute
        {
            ConcurrentDictionary <Type, Attribute> root;

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