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