Type.GetEvent 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 Type에서 선언되거나 상속된 특정 이벤트를 가져옵니다.
오버로드
| Name | Description |
|---|---|
| GetEvent(String, BindingFlags) |
파생 클래스에서 재정의되는 경우 지정된 바인딩 제약 조건을 사용하여 지정된 이벤트를 나타내는 EventInfo 개체를 반환합니다. |
| GetEvent(String) |
지정된 공용 이벤트를 나타내는 EventInfo 개체를 반환합니다. |
GetEvent(String, BindingFlags)
- Source:
- Type.cs
- Source:
- Type.cs
- Source:
- Type.cs
- Source:
- Type.cs
- Source:
- Type.cs
파생 클래스에서 재정의되는 경우 지정된 바인딩 제약 조건을 사용하여 지정된 이벤트를 나타내는 EventInfo 개체를 반환합니다.
public:
abstract System::Reflection::EventInfo ^ GetEvent(System::String ^ name, System::Reflection::BindingFlags bindingAttr);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicEvents | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicEvents)]
public abstract System.Reflection.EventInfo? GetEvent(string name, System.Reflection.BindingFlags bindingAttr);
public abstract System.Reflection.EventInfo GetEvent(string name, System.Reflection.BindingFlags bindingAttr);
public abstract System.Reflection.EventInfo? GetEvent(string name, System.Reflection.BindingFlags bindingAttr);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicEvents | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicEvents)>]
abstract member GetEvent : string * System.Reflection.BindingFlags -> System.Reflection.EventInfo
abstract member GetEvent : string * System.Reflection.BindingFlags -> System.Reflection.EventInfo
Public MustOverride Function GetEvent (name As String, bindingAttr As BindingFlags) As EventInfo
매개 변수
반품
현재 Type에서 선언하거나 상속하는 지정된 이벤트를 나타내는 개체입니다(있는 경우). 그렇지 않으면 null.
구현
- 특성
예외
name은 null입니다.
예제
다음 코드 예제에서는 GetEvent(String, BindingFlags) 메서드를 사용하여 static(Visual Basic Shared)이 아닌 "Click"이라는 공용 또는 비공용 이벤트에 대한 형식을 검색합니다.
using System;
using System.Reflection;
using System.Security;
class MyEventExample
{
public static void Main()
{
try
{
// Creates a bitmask based on BindingFlags.
BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
Type myTypeBindingFlags = typeof(System.Windows.Forms.Button);
EventInfo myEventBindingFlags = myTypeBindingFlags.GetEvent("Click", myBindingFlags);
if(myEventBindingFlags != null)
{
Console.WriteLine("Looking for the Click event in the Button class with the specified BindingFlags.");
Console.WriteLine(myEventBindingFlags.ToString());
}
else
{
Console.WriteLine("The Click event is not available with the Button class.");
}
}
catch(SecurityException e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Message :"+e.Message);
}
catch(ArgumentNullException e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Message :"+e.Message);
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised : {0}",e.Message);
}
}
}
open System
open System.Reflection
open System.Security
try
// Creates a bitmask based on BindingFlags.
let myBindingFlags = BindingFlags.Instance ||| BindingFlags.Public ||| BindingFlags.NonPublic
let myTypeBindingFlags = typeof<System.Windows.Forms.Button>
let myEventBindingFlags = myTypeBindingFlags.GetEvent("Click", myBindingFlags)
if myEventBindingFlags <> null then
printfn $"Looking for the Click event in the Button class with the specified BindingFlags.\n{myEventBindingFlags}"
else
printfn "The Click event is not available with the Button class."
with
| :? SecurityException as e ->
printfn "An exception occurred."
printfn $"Message :{e.Message}"
| :? ArgumentNullException as e ->
printfn "An exception occurred."
printfn $"Message :{e.Message}"
| e ->
printfn $"The following exception was raised : {e.Message}"
Imports System.Reflection
Imports System.Security
' Compile this sample using the following command line:
' vbc type_getevent.vb /r:"System.Windows.Forms.dll" /r:"System.dll"
Class MyEventExample
Public Shared Sub Main()
Try
' Creates a bitmask comprising BindingFlags.
Dim myBindingFlags As BindingFlags = BindingFlags.Instance Or BindingFlags.Public _
Or BindingFlags.NonPublic
Dim myTypeBindingFlags As Type = GetType(System.Windows.Forms.Button)
Dim myEventBindingFlags As EventInfo = myTypeBindingFlags.GetEvent("Click", myBindingFlags)
If myEventBindingFlags IsNot Nothing Then
Console.WriteLine("Looking for the Click event in the Button class with the specified BindingFlags.")
Console.WriteLine(myEventBindingFlags.ToString())
Else
Console.WriteLine("The Click event is not available with the Button class.")
End If
Catch e As SecurityException
Console.WriteLine("An exception occurred.")
Console.WriteLine("Message :" + e.Message)
Catch e As ArgumentNullException
Console.WriteLine("An exception occurred.")
Console.WriteLine("Message :" + e.Message)
Catch e As Exception
Console.WriteLine("The following exception was raised : {0}", e.Message)
End Try
End Sub
End Class
설명
다음 BindingFlags 필터 플래그를 사용하여 검색에 포함할 이벤트를 정의할 수 있습니다.
반환을 얻으려면
BindingFlags.Instance또는BindingFlags.Static중 하나를 지정해야 합니다.검색에 공용 이벤트를 포함하도록 지정
BindingFlags.Public합니다.비공용 이벤트(즉, 프라이빗, 내부 및 보호된 이벤트)를 검색에 포함하도록 지정
BindingFlags.NonPublic합니다.위계에서
BindingFlags.FlattenHierarchy및public정적 멤버를 포함하도록protected을(를) 지정하세요. 상속된 클래스에서는private정적 멤버가 포함되지 않습니다.
다음 BindingFlags 한정자 플래그를 사용하여 검색 작동 방식을 변경할 수 있습니다.
BindingFlags.IgnoreCase의 대소문자를 무시합니다.BindingFlags.DeclaredOnly단순히 상속된 이벤트가 아니라 선언 Type된 이벤트만 검색합니다.
자세한 내용은 System.Reflection.BindingFlags을 참조하세요.
이벤트가 퍼블릭인 메서드 또는 접근자가 하나 이상 있는 경우 이벤트를 리플렉션하기 위해 공용으로 간주됩니다. 그렇지 않으면 이벤트가 프라이빗으로 간주되며 BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static(Visual Basic에서는 Or)를 사용하여 값을 결합해야 합니다.
현재 Type 가 생성된 제네릭 형식을 나타내는 경우 이 메서드는 적절한 형식 인수로 대체된 형식 매개 변수를 반환 EventInfo 합니다.
현재 Type 제네릭 형식 또는 제네릭 메서드 정의에서 형식 매개 변수를 나타내는 경우 이 메서드는 클래스 제약 조건의 이벤트를 검색합니다.
추가 정보
적용 대상
GetEvent(String)
- Source:
- Type.cs
- Source:
- Type.cs
- Source:
- Type.cs
- Source:
- Type.cs
- Source:
- Type.cs
지정된 공용 이벤트를 나타내는 EventInfo 개체를 반환합니다.
public:
System::Reflection::EventInfo ^ GetEvent(System::String ^ name);
public:
virtual System::Reflection::EventInfo ^ GetEvent(System::String ^ name);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicEvents)]
public System.Reflection.EventInfo? GetEvent(string name);
public System.Reflection.EventInfo GetEvent(string name);
public System.Reflection.EventInfo? GetEvent(string name);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicEvents)>]
member this.GetEvent : string -> System.Reflection.EventInfo
member this.GetEvent : string -> System.Reflection.EventInfo
abstract member GetEvent : string -> System.Reflection.EventInfo
override this.GetEvent : string -> System.Reflection.EventInfo
Public Function GetEvent (name As String) As EventInfo
매개 변수
반품
현재 Type에서 선언하거나 상속하는 지정된 public 이벤트를 나타내는 개체입니다(있는 경우). 그렇지 않으면 null.
구현
- 특성
예외
name은 null입니다.
예제
다음 예제에서는 개체를 EventInfo 만들고 지정 된 이벤트에 대 한 단추 클래스에 대 한 이벤트를 가져옵니다.
using System;
using System.Reflection;
using System.Security;
class MyEventExample
{
public static void Main()
{
try
{
Type myType = typeof(System.Windows.Forms.Button);
EventInfo myEvent = myType.GetEvent("Click");
if(myEvent != null)
{
Console.WriteLine("Looking for the Click event in the Button class.");
Console.WriteLine(myEvent.ToString());
}
else
{
Console.WriteLine("The Click event is not available in the Button class.");
}
}
catch(SecurityException e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Message :"+e.Message);
}
catch(ArgumentNullException e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Message :"+e.Message);
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised : {0}",e.Message);
}
}
}
open System
open System.Security
try
let myType = typeof<System.Windows.Forms.Button>
let myEvent = myType.GetEvent "Click"
if myEvent <> null then
printfn $"Looking for the Click event in the Button class.\n{myEvent}"
else
printfn "The Click event is not available in the Button class."
with
| :? SecurityException as e ->
printfn "An exception occurred."
printfn $"Message :{e.Message}"
| :? ArgumentNullException as e ->
printfn "An exception occurred."
printfn $"Message :{e.Message}"
| e ->
printfn $"The following exception was raised : {e.Message}"
Imports System.Reflection
Imports System.Security
' Compile this sample using the following command line:
' vbc type_getevent.vb /r:"System.Windows.Forms.dll" /r:"System.dll"
Class MyEventExample
Public Shared Sub Main()
Try
Dim myType As Type = GetType(System.Windows.Forms.Button)
Dim myEvent As EventInfo = myType.GetEvent("Click")
If Not (myEvent Is Nothing) Then
Console.WriteLine(ControlChars.Cr + "Looking for the Click event in the Button class.")
Console.WriteLine(ControlChars.Cr + myEvent.ToString())
Else
Console.WriteLine("The Click event is not available with the Button class.")
End If
Catch e As SecurityException
Console.WriteLine("An exception occurred.")
Console.WriteLine("Message :" + e.Message)
Catch e As ArgumentNullException
Console.WriteLine("An exception occurred.")
Console.WriteLine("Message :" + e.Message)
Catch e As Exception
Console.WriteLine("The following exception was raised : {0}", e.Message)
End Try
End Sub
End Class
설명
이벤트가 퍼블릭인 메서드 또는 접근자가 하나 이상 있는 경우 이벤트를 리플렉션하기 위해 공용으로 간주됩니다. 그렇지 않으면 이벤트가 프라이빗으로 간주되며 BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static(Visual Basic에서는 Or)를 사용하여 값을 결합해야 합니다.
검색에서 name은 대/소문자를 구분합니다. 검색에는 퍼블릭 정적 및 공용 인스턴스 이벤트가 포함됩니다.
다음 표에서는 형식을 반영할 때 메서드에서 반환되는 기본 클래스의 Get 멤버를 보여 줍니다.
| 멤버 형식 | Static | 비정적 |
|---|---|---|
| 생성자 | No | No |
| Field | No | Yes. 필드는 항상 이름과 서명을 기준으로 숨겨집니다. |
| 이벤트 | 적용할 수 없음 | 일반적인 형식 시스템 규칙은 상속이 속성을 구현하는 메서드의 상속과 동일하다는 것입니다. 리플렉션은 속성을 이름별 숨기기 및 서명으로 처리합니다. 아래 참고 2를 참조하세요. |
| Method | No | Yes. 메서드(가상 및 가상이 아닌 메서드)는 이름으로 숨기기 또는 이름과 서명으로 숨기기가 가능합니다. |
| 중첩 타입 | No | No |
| 재산 | 적용할 수 없음 | 일반적인 형식 시스템 규칙은 상속이 속성을 구현하는 메서드의 상속과 동일하다는 것입니다. 리플렉션은 속성을 이름별 숨기기 및 서명으로 처리합니다. 아래 참고 2를 참조하세요. |
이름별 및 서명에 의한 숨기기는 사용자 지정 한정자, 반환 형식, 매개 변수 형식, 센티넬 및 비관리 호출 규칙을 포함하여 서명의 모든 부분을 고려합니다. 이진 비교입니다.
리플렉션의 경우 속성과 이벤트는 이름 및 서명별로 숨겨집니다. 기본 클래스에 get 및 set 접근자가 모두 있는 속성이 있지만 파생 클래스에 get 접근자만 있는 경우 파생 클래스 속성은 기본 클래스 속성을 숨기며 기본 클래스의 setter에 액세스할 수 없습니다.
사용자 지정 특성은 공용 형식 시스템의 일부가 아닙니다.
현재 Type 가 생성된 제네릭 형식을 나타내는 경우 이 메서드는 적절한 형식 인수로 대체된 형식 매개 변수를 반환 EventInfo 합니다.
현재 Type 제네릭 형식 또는 제네릭 메서드 정의에서 형식 매개 변수를 나타내는 경우 이 메서드는 클래스 제약 조건의 이벤트를 검색합니다.