Type.GetEventとは? わかりやすく解説

Type.GetEvent メソッド


Type.GetEvent メソッド (String, BindingFlags)

派生クラスによってオーバーライドされた場合指定したバインディング制約使用して指定したイベントを表す EventInfo オブジェクト返します

名前空間: System
アセンブリ: 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)
public abstract EventInfo GetEvent (
    string name,
    BindingFlags bindingAttr
)
public:
virtual EventInfo^ GetEvent (
    String^ name, 
    BindingFlags bindingAttr
) abstract
public abstract EventInfo GetEvent (
    String name, 
    BindingFlags bindingAttr
)
public abstract function GetEvent (
    name : String, 
    bindingAttr : BindingFlags
) : EventInfo

パラメータ

name

現在の Type宣言または継承されているイベントの名前を格納する String

bindingAttr

検索実行方法指定する 1 つ上の BindingFlags から成るビット マスク

または

null 参照 (Visual Basic では Nothing) を返す 0。

戻り値
現在の Type宣言または継承されている指定イベント存在する場合は、そのイベントを表す EventInfo オブジェクトそれ以外場合null 参照 (Visual Basic では Nothing)。

例外例外
例外種類条件

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

解説解説

次の BindingFlags フィルタ フラグは、検索対象含めイベント定義するために使用できます

次の 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
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
EventInfo
String クラス
BindingFlags
DefaultBinder
ReflectionPermission
GetEvents

Type.GetEvent メソッド (String)

指定したパブリック イベントを表す EventInfo オブジェクト返します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Function GetEvent ( _
    name As String _
) As EventInfo
Dim instance As Type
Dim name As String
Dim returnValue As EventInfo

returnValue = instance.GetEvent(name)
public EventInfo GetEvent (
    string name
)
public:
virtual EventInfo^ GetEvent (
    String^ name
) sealed
public final EventInfo GetEvent (
    String name
)
public final function GetEvent (
    name : String
) : EventInfo

パラメータ

name

現在の Type宣言または継承されているイベントの名前を格納する String

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

例外例外
例外種類条件

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

解説解説

name検索では大文字と小文字区別されます。検索には、public static および publicインスタンス イベント含まれます。

要求された型がパブリックではなく呼び出し元に現在のアセンブリ外の非パブリック オブジェクトリフレクションするための ReflectionPermission がない場合、このメソッドnull 参照 (Visual Basic では Nothing) を返します

型に対すリフレクション時に Get メソッドによって返される基本クラスメンバ次の表に示します

  1. 名前と署名による隠ぺいでは、カスタム修飾子戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約含めて署名すべての部分判断対象となります。これはバイナリ比較です。

  2. リフレクション場合プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスget アクセサset アクセサ両方を持つプロパティがあり、派生クラスには get アクセサしかない場合派生クラスプロパティにより基本クラスプロパティ隠ぺいされ、基本クラスset アクセサにはアクセスできません。

  3. カスタム属性は、共通型システム一部ではありません。

現在の 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
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

_Type.GetEvent メソッド



このページでは「.NET Framework クラス ライブラリ リファレンス」からType.GetEventを検索した結果を表示しています。
Weblioに収録されているすべての辞書からType.GetEventを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からType.GetEvent を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Type.GetEvent」の関連用語

Type.GetEventのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Type.GetEventのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS