コード例 #1
0
        /// <summary>
        /// Return the first found custom attribute on a method
        /// </summary>
        /// <param name="attributeType">type of the custom attribute</param>
        /// <returns>the first found custom attribute; or null none is found</returns>
        public static T GetFirstCustomAttribute <T>(this IMethodInfo me) where T : Attribute
        {
            IAttributeInfo attrInfo = null;

            foreach (var a in me.GetCustomAttributes(typeof(T)))
            {
                attrInfo = a;
                break;
            }

            return(attrInfo != null?attrInfo.GetInstance <T>() : null);
        }
コード例 #2
0
        /// <summary>
        /// Return the first found custom attribute
        /// </summary>
        /// <param name="attributeType">type of the custome attribute</param>
        /// <returns>the first found custom attribute; or null none is found</returns>
        public static T GetFirstCustomAttribute <T>(this ITypeInfo me) where T : Attribute
        {
            IAttributeInfo attrInfo = null;

            foreach (var a in me.GetCustomAttributes(typeof(T)))
            {
                attrInfo = a;
                break;
            }

            if (attrInfo != null)
            {
                return(attrInfo.GetInstance <T>());
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
 public T GetInstance <T>() where T : Attribute
 {
     return((T)_originalAttribute.GetInstance <T>());
 }