EventInfo クラス
定義
イベントの属性を取得し、イベントのメタデータにアクセスできるようにします。Discovers the attributes of an event and provides access to event metadata.
public ref class EventInfo abstract : System::Reflection::MemberInfo, System::Runtime::InteropServices::_EventInfo
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public abstract class EventInfo : System.Reflection.MemberInfo, System.Runtime.InteropServices._EventInfo
type EventInfo = class
inherit MemberInfo
interface _EventInfo
Public MustInherit Class EventInfo
Inherits MemberInfo
Implements _EventInfo
- 継承
- 派生
- 属性
- 実装
例
次のコードは、 EventInfo ButtonクラスのClickイベントのオブジェクトを取得します。The following code gets an EventInfo object for the Click event of the Button class.
#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 );
}
}
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);
}
}
}
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
注釈
メソッドのコード例に示すように、クラスを使用してイベントを検査し、イベントハンドラーをフックします。EventInfo AddEventHandlerUse the EventInfo class to inspect events and to hook up event handlers, as shown in the example code for the AddEventHandler method.
注意
EventInfoは、イベントを発生させるために使用するためのものではありません。EventInfo is not intended to be used to raise events. オブジェクトは、内部状態で示されているように、イベントを発生させます。An object raises events as dictated by its internal state.
イベントはデリゲートと共に使用されます。Events are used with delegates. イベントリスナーは、イベントソースによってイベントが発生するたびに呼び出されるイベントハンドラーデリゲートをインスタンス化します。An event listener instantiates an event-handler delegate that is invoked whenever the event is raised by an event source. イベントソースに接続するために、イベントリスナーは、このデリゲートをソースの呼び出しリストに追加します。In order to connect to the event source, the event listener adds this delegate to the invocation list on the source. イベントが発生すると、イベントハンドラーデリゲートの invoke メソッドが呼び出されます。When the event is raised, the invoke method of the event-handler delegate is called. マルチキャストイベント通知とシングルキャストイベント通知の両方がサポートされています。Both multicast and single-cast event notifications are supported. イベントAdd
にRemove
関連付けられているイベントハンドラーデリゲートクラスに加えて、メソッドとメソッドは、メタデータでマークされている必要があります。The Add
and Remove
methods, as well as the event-handler delegate class associated with an event, must be marked in the metadata.
デリゲートはオブジェクト指向の関数ポインターです。Delegates are object-oriented function pointers. C またはC++では、関数ポインターはメソッドへの参照です。In C or C++, a function pointer is a reference to a method. C またはC++関数ポインターとは異なり、デリゲートには、メソッドへの参照と、メソッドをサポートするオブジェクトへの参照の2つの参照が含まれます。In contrast to the C or C++ function pointer, a delegate contains two references: a reference to a method and a reference to an object that supports the method. デリゲートは、メソッドを宣言または継承するクラス型を知らなくてもメソッドを呼び出すことができます。Delegates can invoke a method without knowing the class type that declares or inherits the method. デリゲートは、メソッドの戻り値の型とパラメーターリストのみを必要とします。Delegates need only know the return type and parameter list of the method.
イベントモデルは、シングルキャストデリゲートとマルチキャストデリゲートでも同様に機能します。The event model works equally well for single-cast and multicast delegates. デリゲートの invoke メソッドが呼び出されると、1つのオブジェクトに対してメソッドが呼び出されます。When the delegate's invoke method is called, only a single object will have a method called on it. マルチキャスト修飾子はデリゲート宣言に適用できます。これにより、デリゲートの invoke メソッドが呼び出されたときに、複数のメソッドを呼び出すことができます。A multicast modifier can be applied to a delegate declaration, which allows multiple methods to be called when the invoke method of the delegate is called.
のICustomAttributeProvider.GetCustomAttributes inherit
パラメーター EventInfo
がの場合GetCustomAttributes
にを呼び出すと、型階層がウォークされません。 true
Calling ICustomAttributeProvider.GetCustomAttributes on EventInfo
when the inherit
parameter of GetCustomAttributes
is true
does not walk the type hierarchy. カスタムSystem.Attribute属性を継承するには、を使用します。Use System.Attribute to inherit custom attributes.
注意 (実装者)
からEventInfo
継承する場合はGetAddMethod(Boolean)、、 GetRemoveMethod(Boolean)、およびGetRaiseMethod(Boolean)の各メンバーをオーバーライドする必要があります。When you inherit from EventInfo
, you must override the following members: GetAddMethod(Boolean), GetRemoveMethod(Boolean), and GetRaiseMethod(Boolean).
コンストラクター
EventInfo() |
|
プロパティ
AddMethod |
非パブリック メソッドを含む、イベントの MethodInfo メソッドの AddEventHandler(Object, Delegate) オブジェクトを取得します。Gets the MethodInfo object for the AddEventHandler(Object, Delegate) method of the event, including non-public methods. |
Attributes |
このイベントの属性を取得します。Gets the attributes for this event. |
CustomAttributes |
このメンバーのカスタム属性を含むコレクションを取得します。Gets a collection that contains this member's custom attributes. (継承元 MemberInfo) |
DeclaringType |
このメンバーを宣言するクラスを取得します。Gets the class that declares this member. (継承元 MemberInfo) |
EventHandlerType |
このイベントに関連付けられている基になるイベント ハンドラー デリゲートの |
IsCollectible |
この MemberInfo オブジェクトが、収集可能な AssemblyLoadContext に保持されているアセンブリの一部であるかどうかを示す値を取得します。Gets a value that indicates whether this MemberInfo object is part of an assembly held in a collectible AssemblyLoadContext. (継承元 MemberInfo) |
IsMulticast |
イベントがマルチキャストかどうかを示す値を取得します。Gets a value indicating whether the event is multicast. |
IsSpecialName |
|
MemberType |
このメンバーがイベントであることを示す MemberTypes 値を取得します。Gets a MemberTypes value indicating that this member is an event. |
MetadataToken |
メタデータ要素を識別する値を取得します。Gets a value that identifies a metadata element. (継承元 MemberInfo) |
Module |
現在の MemberInfo によって表されるメンバーを宣言する型が定義されているモジュールを取得します。Gets the module in which the type that declares the member represented by the current MemberInfo is defined. (継承元 MemberInfo) |
Name |
現在のメンバーの名前を取得します。Gets the name of the current member. (継承元 MemberInfo) |
RaiseMethod |
イベントの発生時に呼び出されるメソッドを、非パブリック メソッドも含めて取得します。Gets the method that is called when the event is raised, including non-public methods. |
ReflectedType |
|
RemoveMethod |
非パブリック メソッドを含む、イベントのメソッドを削除するための |
メソッド
AddEventHandler(Object, Delegate) |
イベント ソースにイベント ハンドラーを追加します。Adds an event handler to an event source. |
Equals(Object) |
このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。Returns a value that indicates whether this instance is equal to a specified object. |
GetAddMethod() |
イベント ソースにイベント ハンドラー デリゲートを追加するために使用するメソッドを返します。Returns the method used to add an event handler delegate to the event source. |
GetAddMethod(Boolean) |
派生クラスでオーバーライドされた場合は、パブリックでないメソッドを返すかどうかを指定して、イベントの AddEventHandler(Object, Delegate) メソッドの |
GetCustomAttributes(Boolean) |
派生クラスでオーバーライドされた場合、このメンバーに適用されているすべてのカスタム属性の配列を返します。When overridden in a derived class, returns an array of all custom attributes applied to this member. (継承元 MemberInfo) |
GetCustomAttributes(Type, Boolean) |
派生クラスでオーバーライドされた場合は、このメンバーに適用され、Type によって識別されるカスタム属性の配列を返します。When overridden in a derived class, returns an array of custom attributes applied to this member and identified by Type. (継承元 MemberInfo) |
GetCustomAttributesData() |
ターゲット メンバーに適用されている属性に関するデータを表す CustomAttributeData オブジェクトのリストを返します。Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target member. (継承元 MemberInfo) |
GetHashCode() |
このインスタンスのハッシュ コードを返します。Returns the hash code for this instance. |
GetOtherMethods() |
|
GetOtherMethods(Boolean) |
非パブリック メソッドを含めるかどうかを指定して、 |
GetRaiseMethod() |
イベントが発生すると呼び出されるメソッドが返されます。Returns the method that is called when the event is raised. |
GetRaiseMethod(Boolean) |
派生クラスでオーバーライドされた場合は、パブリックでないメソッドを返すかどうかを指定して、イベントが発生したときに呼び出されるメソッドを返します。When overridden in a derived class, returns the method that is called when the event is raised, specifying whether to return non-public methods. |
GetRemoveMethod() |
イベント ソースからイベント ハンドラー デリゲートを削除するために使用するメソッドを返します。Returns the method used to remove an event handler delegate from the event source. |
GetRemoveMethod(Boolean) |
派生クラスでオーバーライドされた場合は、パブリックでないメソッドを返すかどうかを指定して、イベントのメソッドを削除する |
GetType() | |
HasSameMetadataDefinitionAs(MemberInfo) | (継承元 MemberInfo) |
IsDefined(Type, Boolean) |
派生クラスでオーバーライドされた場合、このメンバーに、指定された型の属性またはその派生型の属性が 1 つ以上適用されているかどうかを示します。When overridden in a derived class, indicates whether one or more attributes of the specified type or of its derived types is applied to this member. (継承元 MemberInfo) |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object. (継承元 Object) |
RemoveEventHandler(Object, Delegate) |
イベント ソースからイベント ハンドラーを削除します。Removes an event handler from an event source. |
ToString() |
現在のオブジェクトを表す string を返します。Returns a string that represents the current object. (継承元 Object) |
演算子
Equality(EventInfo, EventInfo) |
2 つの EventInfo オブジェクトが等しいかどうかを示します。Indicates whether two EventInfo objects are equal. |
Inequality(EventInfo, EventInfo) |
2 つの EventInfo オブジェクトが等しくないかどうかを示します。Indicates whether two EventInfo objects are not equal. |
明示的なインターフェイスの実装
_EventInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
一連の名前を対応する一連のディスパッチ識別子に割り当てます。Maps a set of names to a corresponding set of dispatch identifiers. |
_EventInfo.GetType() |
EventInfo 型を表す |
_EventInfo.GetTypeInfo(UInt32, UInt32, IntPtr) |
オブジェクトの型情報を取得します。この型情報を使用して、インターフェイスの型情報を取得できます。Retrieves the type information for an object, which can then be used to get the type information for an interface. |
_EventInfo.GetTypeInfoCount(UInt32) |
オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。Retrieves the number of type information interfaces that an object provides (either 0 or 1). |
_EventInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。Provides access to properties and methods exposed by an object. |
_MemberInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
一連の名前を対応する一連のディスパッチ識別子に割り当てます。Maps a set of names to a corresponding set of dispatch identifiers. (継承元 MemberInfo) |
_MemberInfo.GetType() |
Type クラスを表す MemberInfo オブジェクトを取得します。Gets a Type object representing the MemberInfo class. (継承元 MemberInfo) |
_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr) |
オブジェクトの型情報を取得します。この型情報を使用して、インターフェイスの型情報を取得できます。Retrieves the type information for an object, which can then be used to get the type information for an interface. (継承元 MemberInfo) |
_MemberInfo.GetTypeInfoCount(UInt32) |
オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。Retrieves the number of type information interfaces that an object provides (either 0 or 1). (継承元 MemberInfo) |
_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。Provides access to properties and methods exposed by an object. (継承元 MemberInfo) |
ICustomAttributeProvider.GetCustomAttributes(Boolean) | (継承元 MemberInfo) |
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean) | (継承元 MemberInfo) |
ICustomAttributeProvider.IsDefined(Type, Boolean) | (継承元 MemberInfo) |
拡張メソッド
GetCustomAttribute(MemberInfo, Type) |
指定したメンバーに適用される指定した型のカスタム属性を取得します。Retrieves a custom attribute of a specified type that is applied to a specified member. |
GetCustomAttribute(MemberInfo, Type, Boolean) |
指定したメンバーに適用される指定した型のカスタム属性を取得し、オプションでそのメンバーの先祖を調べます。Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member. |
GetCustomAttribute<T>(MemberInfo) |
指定したメンバーに適用される指定した型のカスタム属性を取得します。Retrieves a custom attribute of a specified type that is applied to a specified member. |
GetCustomAttribute<T>(MemberInfo, Boolean) |
指定したメンバーに適用される指定した型のカスタム属性を取得し、オプションでそのメンバーの先祖を調べます。Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member. |
GetCustomAttributes(MemberInfo) |
指定されたメンバーに適用されるカスタム属性のコレクションを取得します。Retrieves a collection of custom attributes that are applied to a specified member. |
GetCustomAttributes(MemberInfo, Boolean) |
指定されたメンバーに適用されるカスタム属性のコレクションを取得し、オプションでそのメンバーの先祖を調べます。Retrieves a collection of custom attributes that are applied to a specified member, and optionally inspects the ancestors of that member. |
GetCustomAttributes(MemberInfo, Type) |
指定されたメンバーに適用される指定された型のカスタム属性のコレクションを取得します。Retrieves a collection of custom attributes of a specified type that are applied to a specified member. |
GetCustomAttributes(MemberInfo, Type, Boolean) |
指定されたメンバーに適用されている指定された型のカスタム属性のコレクションを取得し、オプションでそのメンバーの先祖を調べます。Retrieves a collection of custom attributes of a specified type that are applied to a specified member, and optionally inspects the ancestors of that member. |
GetCustomAttributes<T>(MemberInfo) |
指定されたメンバーに適用される指定された型のカスタム属性のコレクションを取得します。Retrieves a collection of custom attributes of a specified type that are applied to a specified member. |
GetCustomAttributes<T>(MemberInfo, Boolean) |
指定されたメンバーに適用されている指定された型のカスタム属性のコレクションを取得し、オプションでそのメンバーの先祖を調べます。Retrieves a collection of custom attributes of a specified type that are applied to a specified member, and optionally inspects the ancestors of that member. |
IsDefined(MemberInfo, Type) |
指定された型のカスタム属性が指定されたメンバーに適用されているかどうかを示します。Indicates whether custom attributes of a specified type are applied to a specified member. |
IsDefined(MemberInfo, Type, Boolean) |
指定された型のカスタム属性が指定されたメンバーに適用され、オプションで先祖に適用されているかどうかを示します。Indicates whether custom attributes of a specified type are applied to a specified member, and, optionally, applied to its ancestors. |
GetAddMethod(EventInfo) | |
GetAddMethod(EventInfo, Boolean) | |
GetRaiseMethod(EventInfo) | |
GetRaiseMethod(EventInfo, Boolean) | |
GetRemoveMethod(EventInfo) | |
GetRemoveMethod(EventInfo, Boolean) | |
GetMetadataToken(MemberInfo) |
指定されたメンバーのメタデータ トークンを取得します (存在する場合)。Gets a metadata token for the given member, if available. |
HasMetadataToken(MemberInfo) |
指定されたメンバーに対してメタデータ トークンを使用できるかどうかを示す値を返します。Returns a value that indicates whether a metadata token is available for the specified member. |
セキュリティ
InheritanceDemand
継承者に対する完全な信頼の場合。for full trust for inheritors. このクラスを、部分的に信頼されているコードが継承することはできません。This class cannot be inherited by partially trusted code.
適用対象
スレッド セーフ
この型はスレッド セーフです。This type is thread safe.