Type.GetEvents 메서드

정의

현재 Type에 의해 선언되거나 상속되는 이벤트를 가져옵니다.

오버로드

GetEvents()

현재 Type에 의해 선언되거나 상속되는 모든 public 이벤트를 반환합니다.

GetEvents(BindingFlags)

파생 클래스에서 재정의되면, 현재 Type에 의해 선언되거나 상속되는 이벤트를 지정된 바인딩 제약 조건으로 검색합니다.

GetEvents()

현재 Type에 의해 선언되거나 상속되는 모든 public 이벤트를 반환합니다.

public:
 virtual cli::array <System::Reflection::EventInfo ^> ^ GetEvents();
public virtual System.Reflection.EventInfo[] GetEvents ();
abstract member GetEvents : unit -> System.Reflection.EventInfo[]
override this.GetEvents : unit -> System.Reflection.EventInfo[]
Public Overridable Function GetEvents () As EventInfo()

반환

EventInfo[]

현재 EventInfo에 의해 선언되거나 상속되는 모든 public 이벤트를 나타내는 Type 개체의 배열입니다.

또는 현재 EventInfo에 public 이벤트가 없을 경우 Type 형식의 빈 배열입니다.

구현

예제

다음 예제에서는 개체의 배열을 가져오고 EventInfo , 클래스에 대 한 모든 이벤트를 가져오고, Button 이벤트 이름을 표시 합니다. Visual Basic 예제를 컴파일하려면 다음 명령줄을 사용 합니다.

vbc type_getevents1.vb /r:System.Windows.Forms.dll /r:System.dll

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Security;

int main()
{
   try
   {
      Type^ myType = System::Windows::Forms::Button::typeid;
      array<EventInfo^>^myEvents = myType->GetEvents();
      Console::WriteLine( "The events on the Button class are: " );
      for ( int index = 0; index < myEvents->Length; index++ )
      {
         Console::WriteLine( myEvents[ index ] );

      }
   }
   catch ( SecurityException^ e ) 
   {
      Console::WriteLine( "SecurityException: {0}", e->Message );
   }
   catch ( ArgumentNullException^ e ) 
   {
      Console::WriteLine( "ArgumentNullException: {0}", e->Message );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception: {0}", e->Message );
   }
}
using System;
using System.Reflection;
using System.Security;

class EventsSample
{
    public static void Main()
    {
        try
        {
            // Creates a bitmask based on BindingFlags.
            BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public;
            Type myTypeEvent = typeof(System.Windows.Forms.Button);
            EventInfo[] myEventsBindingFlags = myTypeEvent.GetEvents(myBindingFlags);
            Console.WriteLine("\nThe events on the Button class with the specified BindingFlags are : ");
            for (int index = 0; index < myEventsBindingFlags.Length; index++)
            {
                Console.WriteLine(myEventsBindingFlags[index].ToString());
            }
        }
        catch(SecurityException e)
        {
            Console.WriteLine("SecurityException :" + e.Message);
        }
        catch(ArgumentNullException e)
        {
            Console.WriteLine("ArgumentNullException : " + e.Message);
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception : " + e.Message);
        }
    }
}
Imports System.Reflection
Imports System.Security

' Compile this sample using the following command line:
' vbc type_getevents.vb /r:"System.Windows.Forms.dll" /r:"System.dll"

Class EventsSample

    Public Shared Sub Main()
        Try
            ' Creates a bitmask based on BindingFlags.
            Dim myBindingFlags As BindingFlags = BindingFlags.Instance Or BindingFlags.Public
            Dim myTypeEvent As Type = GetType(System.Windows.Forms.Button)
            Dim myEventsBindingFlags As EventInfo() = myTypeEvent.GetEvents(myBindingFlags)
            Console.WriteLine(ControlChars.Cr + "The events on the Button class with the specified BindingFlags are : ")
            Dim index As Integer
            For index = 0 To myEventsBindingFlags.Length - 1
                Console.WriteLine(myEventsBindingFlags(index).ToString())
            Next index
        Catch e As SecurityException
            Console.WriteLine(("SecurityException :" + e.Message))
        Catch e As ArgumentNullException
            Console.WriteLine(("ArgumentNullException : " + e.Message))
        Catch e As Exception
            Console.WriteLine(("Exception : " + e.Message))
        End Try
    End Sub
End Class

설명

이벤트는 public 인 메서드나 접근자가 하나 이상 있는 경우 리플렉션에 public으로 간주 됩니다. 그렇지 않으면 이벤트는 전용으로 간주 되며, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static (Visual Basic에서 값을 결합 하 여)를 사용 해야 합니다 Or .

GetEvents메서드는 사전순 또는 선언 순서와 같은 특정 순서로 이벤트를 반환 하지 않습니다. 코드가 반환 되는 순서에 따라 달라 지는 것은 아닙니다.

이 메서드는 파생 클래스에 의해 재정의 될 수 있습니다.

다음 표에서는 Get 형식에 대해 리플렉션할 때 메서드에서 반환 되는 기본 클래스의 멤버를 보여 줍니다.

멤버 형식 정적 비정적
생성자 아니요 아니요
필드 아니요 예. 필드는 항상 이름 및 시그니처로 숨겨집니다.
이벤트 해당 없음 공용 형식 시스템 규칙은 상속이 속성을 구현 하는 메서드와 동일 하다는 것입니다. 리플렉션에서는 속성을 이름으로 숨기기-서명으로 처리 합니다. 아래의 참고 2를 참조 하세요.
메서드 아니요 예. 메서드 (가상 및 비가상)는 이름을 기준으로 숨기 거 나 이름에 따라 숨길 수 있습니다.
중첩 형식 아니요 아니요
속성 해당 없음 공용 형식 시스템 규칙은 상속이 속성을 구현 하는 메서드와 동일 하다는 것입니다. 리플렉션에서는 속성을 이름으로 숨기기-서명으로 처리 합니다. 아래의 참고 2를 참조 하세요.
  1. 이름 및 시그니처는 사용자 지정 한정자, 반환 형식, 매개 변수 형식, 센티널 및 관리 되지 않는 호출 규칙을 포함 하 여 시그니처의 모든 부분을 고려 합니다. 이는 이진 비교입니다.

  2. 리플렉션의 경우 속성과 이벤트는 이름 및 시그니처로 숨겨집니다. 기본 클래스에 get 및 set 접근자가 모두 포함 된 속성이 있지만 파생 클래스에 get 접근자만 있는 경우 파생 클래스 속성은 기본 클래스 속성을 숨기고 기본 클래스의 setter에 액세스할 수 없게 됩니다.

  3. 사용자 지정 특성은 공용 형식 시스템의 일부가 아닙니다.

현재 Type 이 생성 된 제네릭 형식을 나타내는 경우이 메서드는 EventInfo 형식 매개 변수를 적절 한 형식 인수로 대체 하 여 개체를 반환 합니다.

현재 Type 이 제네릭 형식 또는 제네릭 메서드 정의의 형식 매개 변수를 나타내는 경우이 메서드는 클래스 제약 조건의 이벤트를 검색 합니다.

추가 정보

적용 대상

GetEvents(BindingFlags)

파생 클래스에서 재정의되면, 현재 Type에 의해 선언되거나 상속되는 이벤트를 지정된 바인딩 제약 조건으로 검색합니다.

public:
 abstract cli::array <System::Reflection::EventInfo ^> ^ GetEvents(System::Reflection::BindingFlags bindingAttr);
public abstract System.Reflection.EventInfo[] GetEvents (System.Reflection.BindingFlags bindingAttr);
abstract member GetEvents : System.Reflection.BindingFlags -> System.Reflection.EventInfo[]
Public MustOverride Function GetEvents (bindingAttr As BindingFlags) As EventInfo()

매개 변수

bindingAttr
BindingFlags

검색 방법을 지정하는 열거형 값의 비트 조합입니다.

또는

빈 배열을 반환하는 Default입니다.

반환

EventInfo[]

현재 EventInfo에 의해 선언되거나 상속되는 이벤트 중 지정된 바인딩 제약 조건과 일치하는 모든 이벤트를 나타내는 Type 개체의 배열입니다.

또는 현재 EventInfo에 이벤트가 없거나 해당 바인딩 제약 조건과 일치하는 이벤트가 없을 경우 Type 형식의 빈 배열입니다.

구현

예제

다음 예제에서는 EventInfo 지정 된 바인딩 플래그와 일치 하는 개체의 배열을 가져오고, 클래스에 대 한 모든 이벤트를 가져오고, Button 이벤트 이름을 표시 합니다. Visual Basic 예제를 컴파일하려면 다음 명령줄을 사용 합니다.

vbc type_getevents2.vb /r:System.Windows.Forms.dll /r:System.dll

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Security;

int main()
{
   try
   {
      
      // Create a bitmask based on BindingFlags.
      BindingFlags myBindingFlags = static_cast<BindingFlags>(BindingFlags::Instance | BindingFlags::Public);
      Type^ myTypeEvent = System::Windows::Forms::Button::typeid;
      array<EventInfo^>^myEventsBindingFlags = myTypeEvent->GetEvents( myBindingFlags );
      Console::WriteLine( "\nThe events on the Button class with the specified BindingFlags are:" );
      for ( int index = 0; index < myEventsBindingFlags->Length; index++ )
      {
         Console::WriteLine( myEventsBindingFlags[ index ] );

      }
   }
   catch ( SecurityException^ e ) 
   {
      Console::WriteLine( "SecurityException: {0}", e->Message );
   }
   catch ( ArgumentNullException^ e ) 
   {
      Console::WriteLine( "ArgumentNullException: {0}", e->Message );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception: {0}", e->Message );
   }
}
using System;
using System.Reflection;
using System.Security;

class EventsSample
{
    public static void Main()
    {
        try
        {
            // Create a bitmask based on BindingFlags.
            BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public;
            Type myTypeEvent = typeof(System.Windows.Forms.Button);
            EventInfo[] myEventsBindingFlags = myTypeEvent.GetEvents(myBindingFlags);
            Console.WriteLine("\nThe events on the Button class with the specified BindingFlags are:");
            for (int index = 0; index < myEventsBindingFlags.Length; index++)
            {
                Console.WriteLine(myEventsBindingFlags[index].ToString());
            }
        }
        catch(SecurityException e)
        {
            Console.WriteLine("SecurityException:" + e.Message);
        }
        catch(ArgumentNullException e)
        {
            Console.WriteLine("ArgumentNullException: " + e.Message);
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }
    }
}
Imports System.Reflection
Imports System.Security
Imports System.Windows.Forms

Class EventsSample

    Public Shared Sub Main()
        Try
            ' Create a bitmask based on BindingFlags.
            Dim myBindingFlags As BindingFlags = BindingFlags.Instance Or BindingFlags.Public
            Dim myTypeEvent As Type = GetType(System.Windows.Forms.Button)
            Dim myEventsBindingFlags As EventInfo() = myTypeEvent.GetEvents(myBindingFlags)
            Console.WriteLine(ControlChars.Cr + "The events on the Button class with the specified BindingFlags are:")
            Dim index As Integer
            For index = 0 To myEventsBindingFlags.Length - 1
                Console.WriteLine(myEventsBindingFlags(index).ToString())
            Next index
        Catch e As SecurityException
            Console.WriteLine("SecurityException:" + e.Message)
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException: " + e.Message)
        Catch e As Exception
            Console.WriteLine("Exception: " + e.Message)
        End Try
    End Sub
End Class

설명

GetEvents메서드는 사전순 또는 선언 순서와 같은 특정 순서로 이벤트를 반환 하지 않습니다. 코드가 반환 되는 순서에 따라 달라 지는 것은 아닙니다.

다음 BindingFlags 필터 플래그를 사용 하 여 검색에 포함할 이벤트를 정의할 수 있습니다.

  • BindingFlags.Instance반환을 얻으려면 또는 중 하나를 지정 해야 합니다 BindingFlags.Static .

  • BindingFlags.Public검색에 공용 이벤트를 포함 하도록 지정 합니다.

  • BindingFlags.NonPublic검색에 public이 아닌 이벤트 (즉, private, internal 및 protected 이벤트)를 포함 하도록 지정 합니다. 기본 클래스의 보호 된 이벤트와 내부 이벤트만 반환 됩니다. 기본 클래스의 전용 이벤트는 반환 되지 않습니다.

  • BindingFlags.FlattenHierarchy public 계층의 정적 멤버를 포함 하도록 지정 합니다. 상속 된 protected private 클래스의 정적 멤버는 포함 되지 않습니다.

다음 BindingFlags 한정자 플래그를 사용 하 여 검색의 작동 방식을 변경할 수 있습니다.

  • BindingFlags.DeclaredOnly 단순히 상속 된 이벤트가 아니라에 선언 된 이벤트만 검색 합니다 Type .

자세한 내용은 System.Reflection.BindingFlags를 참조하세요.

이벤트는 public 인 메서드나 접근자가 하나 이상 있는 경우 리플렉션에 public으로 간주 됩니다. 그렇지 않으면 이벤트는 전용으로 간주 되며, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static (Visual Basic에서 값을 결합 하 여)를 사용 해야 합니다 Or .

현재 Type 이 생성 된 제네릭 형식을 나타내는 경우이 메서드는 EventInfo 형식 매개 변수를 적절 한 형식 인수로 대체 하 여 개체를 반환 합니다.

현재 Type 이 제네릭 형식 또는 제네릭 메서드 정의의 형식 매개 변수를 나타내는 경우이 메서드는 클래스 제약 조건의 이벤트를 검색 합니다.

추가 정보

적용 대상