System.Type.FindMembers Method

Returns a filtered array of System.Reflection.MemberInfo objects of the specified member type.

Syntax

public virtual System.Reflection.MemberInfo[] FindMembers (System.Reflection.MemberTypes memberType, System.Reflection.BindingFlags bindingAttr, System.Reflection.MemberFilter filter, object filterCriteria)

Parameters

memberType
An object that indicates the type of member to search for.
bindingAttr
A bitmask comprised of one or more System.Reflection.BindingFlags that specify how the search is conducted.
filter
The delegate that does the comparisons, returning true if the member currently being inspected matches the filterCriteria and false otherwise. You can use the FilterAttribute, FilterName, and FilterNameIgnoreCase delegates supplied by this class. The first uses the fields of FieldAttributes, MethodAttributes, and MethodImplAttributes as search criteria, and the other two delegates use String objects as the search criteria.
filterCriteria
The search criteria that determines whether a member is returned in the array of MemberInfo objects.

Returns

A filtered array of System.Reflection.MemberInfo objects of the specified member type.

-or-

An empty array of type System.Reflection.MemberInfo, if the current Type does not have members of type memberType that match the filter criteria.

Remarks

This method can be overridden by a derived class.

Members include properties, methods, fields, events, and so on.

The following System.Reflection.BindingFlags filter flags can be used to define which members to include in the search:

  • You must specify either BindingFlags.Instance or BindingFlags.Static in order to get a return.

  • Specify BindingFlags.Instance to include instance members in the search.

  • Specify BindingFlags.Static to include static members in the search.

  • Specify BindingFlags.Public to include public members in the search.

  • Specify BindingFlags.NonPublic to include non-public members (that is, private, internal, and protected members) in the search.

The following System.Reflection.BindingFlags modifier flags can be used to change how the search works:

  • BindingFlags.DeclaredOnly to search only the members declared on the Type, not members that were simply inherited.

See System.Reflection.BindingFlags for more information.

Valid values for Type.MemberType are defined in System.Reflection.MemberInfo. If no such members are found, an empty array is returned.

To get the class initializer (.cctor) using this method, you must specify System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic (System.Reflection.BindingFlags.Static Or System.Reflection.BindingFlags.NonPublic in Visual Basic). You can also get the class initializer using the Type.TypeInitializer property.

If the current Type represents a type parameter of a generic type or generic method, Type.FindMembers(System.Reflection.MemberTypes, System.Reflection.BindingFlags, System.Reflection.MemberFilter, object) processes any members declared by the class constraint and the interface constraints of the type parameter.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0