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); } }
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)); }