Ejemplo n.º 1
0
        private MemberInfo[] GetMembers(string name, MemberTypes type, BindingFlags bindingAttr)
        {
            var members = new List <MemberInfo>();

            if ((type & MemberTypes.Constructor) != 0)
            {
                AddMatchingMembers(members, name, adapter.GetConstructors(bindingAttr));
            }
            if ((type & MemberTypes.Event) != 0)
            {
                AddMatchingMembers(members, name, adapter.GetEvents(bindingAttr));
            }
            if ((type & MemberTypes.Field) != 0)
            {
                AddMatchingMembers(members, name, adapter.GetFields(bindingAttr));
            }
            if ((type & MemberTypes.Method) != 0)
            {
                AddMatchingMembers(members, name, adapter.GetMethods(bindingAttr));
            }
            if ((type & MemberTypes.Property) != 0)
            {
                AddMatchingMembers(members, name, adapter.GetProperties(bindingAttr));
            }
            if ((type & MemberTypes.NestedType) != 0)
            {
                AddMatchingMembers(members, name, adapter.GetNestedTypes(bindingAttr));
            }

            return(members.ToArray());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Consumes nested types.
 /// </summary>
 /// <param name="typeScope">The scope to be used as the containing scope.</param>
 /// <param name="type">The type whose nested types are to be consumed.</param>
 protected void ConsumeNestedTypes(IPatternScope typeScope, ITypeInfo type)
 {
     foreach (ITypeInfo nestedType in type.GetNestedTypes(NestedTypeBindingFlags))
     {
         typeScope.Consume(nestedType, false, DefaultNestedTypePattern);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Infers whether the type is a test type based on its structure.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Returns true if the type any associated patterns, if it has
        /// non-nested type members (subject to <see cref="GetMemberBindingFlags" />)
        /// with patterns, if it has generic parameters with patterns, or if any
        /// of its nested types satisfy the preceding rules.
        /// </para>
        /// </remarks>
        /// <param name="evaluator">The pattern evaluator.</param>
        /// <param name="type">The type.</param>
        /// <returns>True if the type is likely a test type.</returns>
        protected virtual bool InferTestType(IPatternEvaluator evaluator, ITypeInfo type)
        {
            if (evaluator.HasPatterns(type))
            {
                return(true);
            }

            BindingFlags bindingFlags = GetMemberBindingFlags(type);

            if (HasCodeElementWithPattern(evaluator, type.GetMethods(bindingFlags)) ||
                HasCodeElementWithPattern(evaluator, type.GetProperties(bindingFlags)) ||
                HasCodeElementWithPattern(evaluator, type.GetFields(bindingFlags)) ||
                HasCodeElementWithPattern(evaluator, type.GetEvents(bindingFlags)))
            {
                return(true);
            }

            if (type.IsGenericTypeDefinition && HasCodeElementWithPattern(evaluator, type.GenericArguments))
            {
                return(true);
            }

            if (ShouldConsumeConstructors(type) &&
                HasCodeElementWithPattern(evaluator, type.GetConstructors(ConstructorBindingFlags)))
            {
                return(true);
            }

            foreach (ITypeInfo nestedType in type.GetNestedTypes(NestedTypeBindingFlags))
            {
                if (InferTestType(evaluator, nestedType))
                {
                    return(true);
                }
            }

            return(false);
        }