示例#1
0
 /// <summary>
 /// Returns an array of all attributes defined on this member.
 /// Returns an empty array if no attributes are defined on this member.
 /// </summary>
 /// <param name="inherit">If true, look in base classes for inherited custom attributes.</param>
 public static object[] GetCustomAttributes(IAnnotatedElement member, bool inherit)
 {
     var attributes = GetAttributes(member, inherit);
     if (attributes == null)
         return new object[0];
     var list = new ArrayList<object>();
     foreach (var attr in attributes.Attributes())
     {
         list.Add(GetAttribute(attr));
     }
     return list.ToArray();
 }
示例#2
0
 /// <summary>
 /// are one or more attributes of the given type defined on this member.
 /// </summary>
 /// <param name="attributeType">The type of the custom attribute</param>
 /// <param name="inherit">If true, look in base classes for inherited custom attributes.</param>
 public static bool IsDefined(IAnnotatedElement member, Type attributeType, bool inherit)
 {
     var attributes = GetAttributes(member, inherit);
     if (attributes == null)
         return false;
     foreach (var attr in attributes.Attributes())
     {
         if (Equals(attr.AttributeType(), attributeType))
         {
             return true;
         }
     }
     return false;
 }
示例#3
0
        /// <summary>
        /// Returns an array of all attributes defined on this member of the given attribute type.
        /// Returns an empty array if no attributes are defined on this member.
        /// </summary>
        /// <param name="inherit">If true, look in base classes for inherited custom attributes.</param>
        public static object[] GetCustomAttributes(IAnnotatedElement member, Type attributeType, bool inherit)
        {
            var attributes = GetAttributes(member, inherit);

            if (attributes == null)
            {
                return(new object[0]);
            }
            var list = new ArrayList <object>();

            foreach (var attr in attributes.Attributes())
            {
                if (Equals(attr.AttributeType(), attributeType))
                {
                    list.Add(GetAttribute(attr));
                }
            }
            return(list.ToArray());
        }
示例#4
0
 /// <summary>
 /// Gets the IAttributes annotation declared in the given member (if any).
 /// </summary>
 private static IAttributes GetAttributes(IAnnotatedElement member, bool inherit)
 {
     var provider = member as IAttributesProvider;
     if (provider != null) return provider.Attributes();
     return member.GetAnnotation<IAttributes>(typeof(IAttributes));
 }
 /// <summary>
 /// Returns an array of all attributes defined on this member of the given attribute type.
 /// Returns an empty array if no attributes are defined on this member.
 /// </summary>
 /// <param name="inherit">If true, look in base classes for inherited custom attributes.</param>
 public static object[] GetCustomAttributes(IAnnotatedElement member, Type attributeType, bool inherit)
 {
     var attributes = GetAttributes(member, inherit);
     return GetCustomAttributes(attributeType, attributes);
 }
 /// <summary>
 /// Gets the IAttributes annotation declared in the given member (if any).
 /// </summary>
 private static IAttributes GetAttributes(IAnnotatedElement member, bool inherit)
 {
     return member.GetAnnotation<IAttributes>(typeof(IAttributes));
 }
 /// <summary>
 /// are one or more attributes of the given type defined on this member.
 /// </summary>
 /// <param name="attributeType">The type of the custom attribute</param>
 /// <param name="inherit">If true, look in base classes for inherited custom attributes.</param>
 public static bool IsDefined(IAnnotatedElement member, Type attributeType, bool inherit)
 {
     var attributes = GetAttributes(member, inherit);
     return IsDefined(attributeType, attributes);
 }
        /// <summary>
        /// Returns an array of all attributes defined on this member of the given attribute type.
        /// Returns an empty array if no attributes are defined on this member.
        /// </summary>
        /// <param name="inherit">If true, look in base classes for inherited custom attributes.</param>
        public static object[] GetCustomAttributes(IAnnotatedElement member, Type attributeType, bool inherit)
        {
            var attributes = GetAttributes(member, inherit);

            return(GetCustomAttributes(attributeType, attributes));
        }
        /// <summary>
        /// are one or more attributes of the given type defined on this member.
        /// </summary>
        /// <param name="attributeType">The type of the custom attribute</param>
        /// <param name="inherit">If true, look in base classes for inherited custom attributes.</param>
        public static bool IsDefined(IAnnotatedElement member, Type attributeType, bool inherit)
        {
            var attributes = GetAttributes(member, inherit);

            return(IsDefined(attributeType, attributes));
        }