Пример #1
0
        private TAttribute RetrieveAttribute <TAttribute>(PairKey <Type, Type> key, bool inherit)
            where TAttribute : Attribute
        {
            TAttribute attribute = (TAttribute)Attribute.GetCustomAttribute(key.Left, typeof(TAttribute), inherit);

            return(attribute);
        }
Пример #2
0
        public override bool Equals(object obj)
        {
            PairKey <TLeft, TRight> other = obj as PairKey <TLeft, TRight>;

            if (other == null)
            {
                return(false);
            }
            return(Equals(left, other.left) && Equals(right, other.right));
        }
Пример #3
0
        private TAttribute DoGetCustomAttribute <TAttribute>(Type type, Dictionary <PairKey <Type, Type>, Attribute> cache, object lockObject, bool inherit)
            where TAttribute : Attribute
        {
            PairKey <Type, Type> key = new PairKey <Type, Type>(type, typeof(TAttribute));
            Attribute            storedObject;
            bool exists = false;

            lock (lockObject)
            {
                exists = cache.TryGetValue(key, out storedObject);
            }
            if (!exists)
            {
                storedObject = RetrieveAttribute <TAttribute>(key, inherit);
                lock (lockObject)
                {
                    cache[key] = storedObject;
                }
            }
            return(storedObject as TAttribute);
        }
Пример #4
0
        public bool HasCachedCustomAttribute <TAttribute>(Type type)
        {
            PairKey <Type, Type> key = new PairKey <Type, Type>(type, typeof(TAttribute));

            return(this.typeAttributes.ContainsKey(key));
        }