Type.GetEvent メソッド

名前 | 説明 |
---|---|
Type.GetEvent (String) | 指定したパブリック イベントを表す EventInfo オブジェクトを返します。 .NET Compact Framework によってサポートされています。 |
Type.GetEvent (String, BindingFlags) | 派生クラスによってオーバーライドされた場合、指定したバインディング制約を使用して、指定したイベントを表す EventInfo オブジェクトを返します。 .NET Compact Framework によってサポートされています。 |

Type.GetEvent メソッド (String, BindingFlags)
アセンブリ: mscorlib (mscorlib.dll 内)

Public MustOverride Function GetEvent ( _ name As String, _ bindingAttr As BindingFlags _ ) As EventInfo
Dim instance As Type Dim name As String Dim bindingAttr As BindingFlags Dim returnValue As EventInfo returnValue = instance.GetEvent(name, bindingAttr)
- bindingAttr
検索の実行方法を指定する 1 つ以上の BindingFlags から成るビット マスク。
または
null 参照 (Visual Basic では Nothing) を返す 0。
現在の Type で宣言または継承されている指定イベントが存在する場合は、そのイベントを表す EventInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


次の BindingFlags フィルタ フラグは、検索対象に含めるイベントを定義するために使用できます。
-
戻り値を取得するには、BindingFlags.Instance または BindingFlags.Static のいずれかを指定する必要があります。
-
検索対象にパブリックではないイベント (つまり、プライベート イベントやプロテクト イベント) を含めるための BindingFlags.NonPublic を指定します。
-
階層構造の上位にある public 静的メンバおよび protected 静的メンバを検索対象に含めるには、BindingFlags.FlattenHierarchy を指定します。継承クラスの private 静的メンバは含まれません。
次の BindingFlags 修飾フラグは、検索方法を変更するために使用できます。
詳細については、「System.Reflection.BindingFlags」を参照してください。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
現在の Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて EventInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のイベントを検索します。

Imports System Imports System.Reflection Imports System.Security Imports Microsoft.VisualBasic ' 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 Not (myEventBindingFlags Is 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 'Main End Class 'MyEventExample
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); } } }
#using <System.dll> #using <System.Windows.Forms.dll> #using <System.Drawing.dll> using namespace System; using namespace System::Reflection; using namespace System::Security; using namespace System::Windows::Forms; int main() { try { // Creates a bitmask based on BindingFlags. BindingFlags myBindingFlags = static_cast<BindingFlags>(BindingFlags::Instance | BindingFlags::Public | BindingFlags::NonPublic); Type^ myTypeBindingFlags = System::Windows::Forms::Button::typeid; EventInfo^ myEventBindingFlags = myTypeBindingFlags->GetEvent( "Click", myBindingFlags ); if ( myEventBindingFlags != nullptr ) { Console::WriteLine( "Looking for the Click event in the Button class with the specified BindingFlags." ); Console::WriteLine( myEventBindingFlags ); } else Console::WriteLine( "The Click event is not available with the Button class." ); } catch ( SecurityException^ e ) { Console::WriteLine( "An exception occurred." ); Console::WriteLine( "Message : {0}", e->Message ); } catch ( ArgumentNullException^ e ) { Console::WriteLine( "An exception occurred." ); Console::WriteLine( "Message : {0}", e->Message ); } catch ( Exception^ e ) { Console::WriteLine( "The following exception was raised : {0}", e->Message ); } }
import System.*; import System.Reflection.*; import System.Security.*; class MyEventExample { public static void main(String[] args) { try { // Creates a bitmask based on BindingFlags. BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; Type myTypeBindingFlags = System.Windows.Forms.Button.class.ToType(); 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.get_Message()); } catch (ArgumentNullException e) { Console.WriteLine("An exception occurred."); Console.WriteLine("Message :" + e.get_Message()); } catch (System.Exception e) { Console.WriteLine("The following exception was raised : {0}" , e.get_Message()); } } //main } //MyEventExample


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetEvent メソッド (String)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim name As String Dim returnValue As EventInfo returnValue = instance.GetEvent(name)
戻り値
現在の Type で宣言または継承されている指定パブリック イベントが存在する場合は、そのイベントを表す EventInfo オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing)。


name の検索では大文字と小文字が区別されます。検索には、public static および public のインスタンス イベントが含まれます。
要求された型がパブリックではなく、呼び出し元に現在のアセンブリ外の非パブリック オブジェクトをリフレクションするための ReflectionPermission がない場合、このメソッドは null 参照 (Visual Basic では Nothing) を返します。
型に対するリフレクション時に Get メソッドによって返される基本クラスのメンバを次の表に示します。
メンバ型 | 非静的 | |
---|---|---|
いいえ | いいえ | |
いいえ | ||
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 | |
いいえ | はい。メソッド (仮想メソッドと非仮想メソッドの両方) は、名前によって隠蔽することもできますし、名前と署名によって隠蔽することもできます。 | |
いいえ | いいえ | |
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 |
-
名前と署名による隠ぺいでは、カスタム修飾子、戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約を含めて、署名のすべての部分が判断の対象となります。これはバイナリ比較です。
-
リフレクションの場合、プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスに get アクセサと set アクセサの両方を持つプロパティがあり、派生クラスには get アクセサしかない場合、派生クラスのプロパティにより基本クラスのプロパティが隠ぺいされ、基本クラスの set アクセサにはアクセスできません。
現在の Type が構築ジェネリック型を表している場合、このメソッドは、型パラメータを適切な型の引数で置き換えて EventInfo を返します。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約のイベントを検索します。

EventInfo オブジェクトを作成し、指定したイベントのボタン クラスのイベントを取得する例を次に示します。
Imports System Imports System.Reflection Imports System.Security Imports Microsoft.VisualBasic ' 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 'Main End Class 'MyEventExample
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); } } }
#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; EventInfo^ myEvent = myType->GetEvent( "Click" ); if ( myEvent != nullptr ) { Console::WriteLine( "Looking for the Click event in the Button class." ); Console::WriteLine( myEvent ); } else Console::WriteLine( "The Click event is not available in the Button class." ); } catch ( SecurityException^ e ) { Console::WriteLine( "An exception occurred." ); Console::WriteLine( "Message : {0}", e->Message ); } catch ( ArgumentNullException^ e ) { Console::WriteLine( "An exception occurred." ); Console::WriteLine( "Message : {0}", e->Message ); } catch ( Exception^ e ) { Console::WriteLine( "The following exception was raised : {0}", e->Message ); } }
import System.*; import System.Reflection.*; import System.Security.*; class MyEventExample { public static void main(String[] args) { try { Type myType = System.Windows.Forms.Button.class.ToType(); 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.get_Message()); } catch (ArgumentNullException e) { Console.WriteLine("An exception occurred."); Console.WriteLine("Message :" + e.get_Message()); } catch (System.Exception e) { Console.WriteLine("The following exception was raised : {0}" , e.get_Message()); } } //main } //MyEventExample


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


_Type.GetEvent メソッド
Weblioに収録されているすべての辞書からType.GetEventを検索する場合は、下記のリンクをクリックしてください。

- Type.GetEventのページへのリンク