예제 #1
0
 public IEnumerable <XunitAttributeInfo> GetCustomAttributes(Type attributeType)
 {
     foreach (IAttributeInfo attribute in target.GetAttributeInfos(Reflector.Wrap(attributeType), true))
     {
         yield return(new XunitAttributeInfoAdapter(attribute));
     }
 }
예제 #2
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);
        }
예제 #3
0
        /// <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));
        }
예제 #4
0
 /// <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));
 }