示例#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));
        }