public IEnumerable <XunitAttributeInfo> GetCustomAttributes(Type attributeType) { foreach (IAttributeInfo attribute in target.GetAttributeInfos(Reflector.Wrap(attributeType), true)) { yield return(new XunitAttributeInfoAdapter(attribute)); } }
/// <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); }
/// <summary> /// Creates a constant value that wraps an existing native value. /// </summary> /// <param name="value">The native value.</param> /// <returns>The constant.</returns> public static ConstantValue FromNative(object value) { Type valueType = value != null?value.GetType() : typeof(object); return(new ConstantValue(Reflector.Wrap(valueType), value)); }
/// <summary> /// Returns true if the code element has an attribute 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>True if the code element has at least one attribute of the specified type.</returns> public static bool HasAttribute(ICodeElementInfo element, Type attributeType, bool inherit) { return(element.HasAttribute(Reflector.Wrap(attributeType), inherit)); }