Type.FindMembers(MemberTypes, BindingFlags, MemberFilter, Object) Type.FindMembers(MemberTypes, BindingFlags, MemberFilter, Object) Type.FindMembers(MemberTypes, BindingFlags, MemberFilter, Object) Type.FindMembers(MemberTypes, BindingFlags, MemberFilter, Object) Method

정의

지정된 멤버 형식의 MemberInfo 개체에 대한 필터링된 배열을 반환합니다.Returns a filtered array of MemberInfo objects of the specified member type.

public:
 virtual cli::array <System::Reflection::MemberInfo ^> ^ FindMembers(System::Reflection::MemberTypes memberType, System::Reflection::BindingFlags bindingAttr, System::Reflection::MemberFilter ^ filter, System::Object ^ filterCriteria);
public virtual System.Reflection.MemberInfo[] FindMembers (System.Reflection.MemberTypes memberType, System.Reflection.BindingFlags bindingAttr, System.Reflection.MemberFilter filter, object filterCriteria);
abstract member FindMembers : System.Reflection.MemberTypes * System.Reflection.BindingFlags * System.Reflection.MemberFilter * obj -> System.Reflection.MemberInfo[]
override this.FindMembers : System.Reflection.MemberTypes * System.Reflection.BindingFlags * System.Reflection.MemberFilter * obj -> System.Reflection.MemberInfo[]
Public Overridable Function FindMembers (memberType As MemberTypes, bindingAttr As BindingFlags, filter As MemberFilter, filterCriteria As Object) As MemberInfo()

매개 변수

memberType
MemberTypes MemberTypes MemberTypes MemberTypes

검색할 멤버 형식을 나타내는 열거형 값의 비트 조합입니다.A bitwise combination of the enumeration values that indicates the type of member to search for.

bindingAttr
BindingFlags BindingFlags BindingFlags BindingFlags

검색 방법을 지정하는 열거형 값의 비트 조합입니다.A bitwise combination of the enumeration values that specify how the search is conducted.

또는-or- null을 반환하는 Default입니다.Default to return null.

filter
MemberFilter MemberFilter MemberFilter MemberFilter

비교를 수행하여 현재 검사 중인 멤버가 true와 일치하면 filterCriteria이고, 그렇지 않으면 false인 대리자입니다.The delegate that does the comparisons, returning true if the member currently being inspected matches the filterCriteria and false otherwise.

filterCriteria
Object Object Object Object

MemberInfo 개체의 배열에 멤버가 반환되는지를 결정하는 검색 조건입니다.The search criteria that determines whether a member is returned in the array of MemberInfo objects.

FieldAttributes, MethodAttributesMethodImplAttributes의 필드는 이 클래스에서 제공하는 FilterAttribute 대리자와 함께 사용할 수 있습니다.The fields of FieldAttributes, MethodAttributes, and MethodImplAttributes can be used in conjunction with the FilterAttribute delegate supplied by this class.

반환

지정된 멤버 형식의 MemberInfo 개체에 대한 필터링된 배열입니다.A filtered array of MemberInfo objects of the specified member type.

또는-or- 현재 Type에 필터 조건과 일치하는 memberType 형식의 멤버가 없으면 빈 배열입니다.An empty array if the current Type does not have members of type memberType that match the filter criteria.

구현

예외

예제

다음 예제에서는 지정 된 검색 조건과 일치 하는 클래스에서 모든 멤버를 찾아서 다음 일치 하는 멤버를 표시 합니다.The following example finds all the members in a class that match the specified search criteria, and then displays the matched members.

using namespace System;
using namespace System::Reflection;
ref class MyFindMembersClass
{
public:
   static void Test()
   {
      Object^ objTest = gcnew Object;
      Type^ objType = objTest->GetType();
      array<MemberInfo^>^arrayMemberInfo;
      try
      {
         
         //Find all static or public methods in the Object class that match the specified name.
         arrayMemberInfo = objType->FindMembers( MemberTypes::Method, static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static | BindingFlags::Instance), gcnew MemberFilter( DelegateToSearchCriteria ), "ReferenceEquals" );
         for ( int index = 0; index < arrayMemberInfo->Length; index++ )
            Console::WriteLine( "Result of FindMembers -\t {0}", String::Concat( arrayMemberInfo[ index ], "\n" ) );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Exception : {0}", e );
      }

   }

   static bool DelegateToSearchCriteria( MemberInfo^ objMemberInfo, Object^ objSearch )
   {
      
      // Compare the name of the member function with the filter criteria.
      if ( objMemberInfo->Name->Equals( objSearch->ToString() ) )
            return true;
      else
            return false;
   }

};

int main()
{
   MyFindMembersClass::Test();
}

using System;
using System.Reflection;

class MyFindMembersClass
{
    public static void Main()
    {
        Object objTest = new Object();
        Type objType = objTest.GetType ();
        MemberInfo[] arrayMemberInfo;
        try
        {
            //Find all static or public methods in the Object class that match the specified name.
            arrayMemberInfo = objType.FindMembers(MemberTypes.Method,
                BindingFlags.Public | BindingFlags.Static| BindingFlags.Instance,
                new MemberFilter(DelegateToSearchCriteria),
                "ReferenceEquals");

            for(int index=0;index < arrayMemberInfo.Length ;index++)
                Console.WriteLine ("Result of FindMembers -\t"+ arrayMemberInfo[index].ToString() +"\n");                 
        }
        catch (Exception e)
        {
            Console.WriteLine ("Exception : " + e.ToString() );            
        }           
    }
    public static bool DelegateToSearchCriteria(MemberInfo objMemberInfo, Object objSearch)
    {
        // Compare the name of the member function with the filter criteria.
        if(objMemberInfo.Name.ToString() == objSearch.ToString())
            return true;
        else 
            return false;
    }
}

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

설명

이 메서드는 파생된 클래스에서 재정의할 수 있습니다.This method can be overridden by a derived class.

멤버 속성, 메서드, 필드, 이벤트 및 등을 포함 합니다.Members include properties, methods, fields, events, and so on.

BindingFlags.Static BindingFlags.Instance bindingAttr BindingFlags.Public BindingFlags.NonPublic 메서드가 멤버 정보를 성공적으로 검색 하려면 인수에 및 중 적어도 하나 이상이 포함 되어야 합니다. FindMembersFor the FindMembers method to successfully retrieve member information, the bindingAttr argument must include at least one of BindingFlags.Instance and BindingFlags.Static, along with at least one of BindingFlags.NonPublic and BindingFlags.Public.

다음 BindingFlags 필터 플래그를 사용 하 여 검색에 포함할 멤버를 정의할 수 있습니다.The following BindingFlags filter flags can be used to define which members to include in the search:

  • 지정 BindingFlags.Instance 검색에서 인스턴스 멤버를 포함 합니다.Specify BindingFlags.Instance to include instance members in the search.

  • 지정 BindingFlags.Static 검색에 정적 멤버를 포함 합니다.Specify BindingFlags.Static to include static members in the search.

  • 지정 BindingFlags.Public 검색에 public 멤버를 포함 합니다.Specify BindingFlags.Public to include public members in the search.

  • 지정 BindingFlags.NonPublic 검색에서 (즉,: private, internal 및 protected 멤버) public이 아닌 멤버를 포함 합니다.Specify BindingFlags.NonPublic to include non-public members (that is, private, internal, and protected members) in the search.

다음 BindingFlags 한정자 플래그를 사용 하 여 검색의 작동 방식을 변경할 수 있습니다.The following BindingFlags modifier flags can be used to change how the search works:

  • BindingFlags.DeclaredOnly 에 선언 된 멤버만 검색 하 여 Type, 상속 된 멤버가 아닌 합니다.BindingFlags.DeclaredOnly to search only the members declared on the Type, not members that were simply inherited.

자세한 내용은 System.Reflection.BindingFlags를 참조하세요.See System.Reflection.BindingFlags for more information.

이 메서드를 사용 하 여 클래스 이니셜라이저 (정적 생성자)를 BindingFlags.Static 가져오려면 ( | BindingFlags.NonPublic BindingFlags.Static Or BindingFlags.NonPublic Visual Basic)를 지정 해야 합니다.To get the class initializer (static constructor) using this method, you must specify BindingFlags.Static | BindingFlags.NonPublic (BindingFlags.StaticOrBindingFlags.NonPublic in Visual Basic). 클래스 이니셜라이저를 사용 하 여 가져올 수도 있습니다는 TypeInitializer 속성입니다.You can also get the class initializer using the TypeInitializer property.

하는 경우 현재 Type 제네릭 형식 또는 제네릭 메서드 형식 매개 변수를 나타내는 FindMembers 클래스 제약 조건 및 형식 매개 변수의 인터페이스 제약 조건으로 선언 된 모든 멤버를 처리 합니다.If the current Type represents a type parameter of a generic type or generic method, FindMembers processes any members declared by the class constraint and the interface constraints of the type parameter.

인수 filter 는 형식의 MemberFilter사용자 지정 대리자 일 수도 있고 다음의 미리 정의 된 대리자 중 하나일 수도 있습니다.The filter argument can be a custom delegate of type MemberFilter, or it can be one of the following predefined delegates:

적용 대상

추가 정보