Пример #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
        /// <summary>
        /// Returns true if there is a cached entry for the attribute type for the given type
        /// </summary>
        /// <remarks>
        /// A null cached entry will return true.
        /// </remarks>
        /// <typeparam name="TAttribute">The type of attribute required.</typeparam>
        /// <param name="type">The type to query for the attribute.</param>
        /// <returns><code>true</code> if the result for the attribute query is in the cache.</returns>
        public bool HasCachedCustomAttribute <TAttribute>(Type type)
        {
            PairKey <Type, Type> key = new PairKey <Type, Type>(type, typeof(TAttribute));

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