Type.FindMembers Method (MemberTypes, BindingFlags, MemberFilter, Object)
Returns a filtered array of MemberInfo objects of the specified member type.
Assembly: mscorlib (in mscorlib.dll)
Public Overridable Function FindMembers ( memberType As MemberTypes, bindingAttr As BindingFlags, filter As MemberFilter, filterCriteria As Object ) As MemberInfo()
An object that indicates the type of member to search for.
A bitmask comprised of one or more BindingFlags that specify how the search is conducted.
Zero, to return null.
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.
The search criteria that determines whether a member is returned in the array of MemberInfo objects.
The fields of FieldAttributes, MethodAttributes, and MethodImplAttributes can be used in conjunction with the FilterAttribute delegate supplied by this class.
Return ValueType: System.Reflection.MemberInfo()
A filtered array of MemberInfo objects of the specified member type.
This method can be overridden by a derived class.
Members include properties, methods, fields, events, and so on.
The following 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 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.
To get the class initializer (.cctor) using this method, you must specify BindingFlags.Static | BindingFlags.NonPublic (BindingFlags.StaticOrBindingFlags.NonPublic in Visual Basic). You can also get the class initializer using the TypeInitializer property.
If the current Type represents a type parameter of a generic type or generic method, processes any members declared by the class constraint and the interface constraints of the type parameter.
The following example finds all the members in a class that match the specified search criteria, and then displays the matched members.
Imports System Imports System.Reflection Imports Microsoft.VisualBasic Class MyFindMembersClass Public Shared Sub Main() Dim objTest As New Object() Dim objType As Type = objTest.GetType() Dim arrayMemberInfo() As MemberInfo Try 'Find all static or public methods in the Object 'class that match the specified name. arrayMemberInfo = objType.FindMembers(MemberTypes.Method, _ BindingFlags.Public Or BindingFlags.Static _ Or BindingFlags.Instance, _ New MemberFilter(AddressOf DelegateToSearchCriteria), _ "ReferenceEquals") Dim index As Integer For index = 0 To arrayMemberInfo.Length - 1 Console.WriteLine("Result of FindMembers -" + ControlChars.Tab + _ arrayMemberInfo(index).ToString() + ControlChars.Cr) Next index Catch e As Exception Console.WriteLine("Exception : " + e.ToString()) End Try End Sub 'Main Public Shared Function DelegateToSearchCriteria _ (ByVal objMemberInfo As MemberInfo, _ ByVal objSearch As Object) As Boolean ' Compare the name of the member function with the filter criteria. If objMemberInfo.Name.ToString() = objSearch.ToString() Then Return True Else Return False End If End Function 'DelegateToSearchCriteria End Class 'MyFindMembersClass
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0