Ejemplo n.º 1
0
 /// <summary>
 /// Gets the attributes of the specified type.
 /// </summary>
 /// <param name="element">The code element.</param>
 /// <param name="inherit">If true, includes inherited attributes.</param>
 /// <typeparam name="T">The attribute type.</typeparam>
 /// <returns>The attributes.</returns>
 public static IEnumerable <T> GetAttributes <T>(ICodeElementInfo element, bool inherit) where T : class
 {
     foreach (T attrib in element.GetAttributes(Reflector.Wrap(typeof(T)), inherit))
     {
         yield return(attrib);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the attributes of the specified type.
 /// </summary>
 /// <param name="element">The code element.</param>
 /// <param name="attributeType">The attribute type.</param>
 /// <param name="inherit">If true, includes inherited attributes.</param>
 /// <returns>The attributes.</returns>
 public static IEnumerable <object> GetAttributes(ICodeElementInfo element, Type attributeType, bool inherit)
 {
     foreach (object attrib in element.GetAttributes(Reflector.Wrap(attributeType), inherit))
     {
         yield return(attrib);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the attribute of the specified type, or null if none.
        /// </summary>
        /// <param name="element">The code element.</param>
        /// <param name="attributeType">The attribute type.</param>
        /// <param name="inherit">If true, includes inherited attributes.</param>
        /// <returns>The attribute, or null if none.</returns>
        /// <exception cref="InvalidOperationException">Thrown if the code element
        /// has multiple attributes of the specified type.</exception>
        public static object GetAttribute(ICodeElementInfo element, Type attributeType, bool inherit)
        {
            IEnumerator <object> en = element.GetAttributes(Reflector.Wrap(attributeType), inherit).GetEnumerator();

            if (!en.MoveNext())
            {
                return(null);
            }

            object attrib = en.Current;

            if (en.MoveNext())
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  "There are multiple instances of attribute '{0}'.", attributeType));
            }

            return(attrib);
        }
 public static object[] GetCustomAttributes(ICodeElementInfo adapter, Type attributeType, bool inherit)
 {
     return GenericCollectionUtils.ToArray(adapter.GetAttributes(Reflector.Wrap(attributeType), inherit));
 }
 public static object[] GetCustomAttributes(ICodeElementInfo adapter, bool inherit)
 {
     return GenericCollectionUtils.ToArray(adapter.GetAttributes(null, inherit));
 }
 public static object[] GetCustomAttributes(ICodeElementInfo adapter, Type attributeType, bool inherit)
 {
     return(GenericCollectionUtils.ToArray(adapter.GetAttributes(Reflector.Wrap(attributeType), inherit)));
 }
 public static object[] GetCustomAttributes(ICodeElementInfo adapter, bool inherit)
 {
     return(GenericCollectionUtils.ToArray(adapter.GetAttributes(null, inherit)));
 }