Ejemplo n.º 1
0
        /// <summary>
        /// Given a test method, returns the attributes (if any) that are of
        /// the decoratingAttribute parameter's type.
        /// </summary>
        /// <param name="method">ITestMethod instance.</param>
        /// <param name="decoratingAttribute">Attribute of interest.</param>
        /// <param name="inherit">Whether to inherit attributes.</param>
        /// <returns>
        /// A collection populated with the Attribute instances.
        /// </returns>
        public static ICollection <Attribute> GetAttributes(ITestMethod method, Type decoratingAttribute, bool inherit)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            else if (decoratingAttribute == null)
            {
                throw new ArgumentNullException("decoratingAttribute");
            }

            // Get the attributes defined on the method
            ICollection <Attribute> attributes = GetAttributes(method.Method, decoratingAttribute, inherit);

            // Get any dynamic attributes for the method
            IEnumerable <Attribute> dynamicAttributes = method.GetDynamicAttributes();

            if (dynamicAttributes != null)
            {
                foreach (Attribute attribute in dynamicAttributes)
                {
                    if (decoratingAttribute.IsAssignableFrom(attribute.GetType()))
                    {
                        attributes.Add(attribute);
                    }
                }
            }

            return(attributes);
        }
        /// <summary>
        /// Given a test method, returns the attributes (if any) that are of 
        /// the decoratingAttribute parameter's type.
        /// </summary>
        /// <param name="method">ITestMethod instance.</param>
        /// <param name="decoratingAttribute">Attribute of interest.</param>
        /// <param name="inherit">Whether to inherit attributes.</param>
        /// <returns>
        /// A collection populated with the Attribute instances.
        /// </returns>
        public static ICollection<Attribute> GetAttributes(ITestMethod method, Type decoratingAttribute, bool inherit)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            else if (decoratingAttribute == null)
            {
                throw new ArgumentNullException("decoratingAttribute");
            }
            
            // Get the attributes defined on the method
            ICollection<Attribute> attributes = GetAttributes(method.Method, decoratingAttribute, inherit);
            
            // Get any dynamic attributes for the method
            IEnumerable<Attribute> dynamicAttributes = method.GetDynamicAttributes();
            if (dynamicAttributes != null)
            {
                foreach (Attribute attribute in dynamicAttributes)
                {
                    if (decoratingAttribute.IsAssignableFrom(attribute.GetType()))
                    {
                        attributes.Add(attribute);
                    }
                }
            }

            return attributes;
        }