Advertisement
jlind0

Untitled

Jul 4th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. private static readonly Lazy<ConcurrentDictionary<Type, Type[]>> InterfacesCachedMappingLazy = new Lazy<ConcurrentDictionary<Type, Type[]>>(() => new ConcurrentDictionary<Type, Type[]>(), LazyThreadSafetyMode.PublicationOnly);
  2.         private static ConcurrentDictionary<Type, Type[]> InterfacesCachedMapping
  3.         {
  4.             get { return InterfacesCachedMappingLazy.Value; }
  5.         }
  6.         public static Type[] GetInterfacesCached(this Type type)
  7.         {
  8.             Type[] interfaces;
  9.             if(!InterfacesCachedMapping.TryGetValue(type, out interfaces))
  10.             {
  11.                 interfaces = type.GetInterfaces();
  12.                 InterfacesCachedMapping.TryAdd(type, interfaces);
  13.             }
  14.             return interfaces;
  15.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement