EventAttributes 列挙体
イベントの属性を指定します。
この列挙体には、メンバ値をビットごとに演算するための FlagsAttribute 属性が含まれています。
<Flags>
<Serializable>
Public Enum EventAttributes
[C#]
[Flags]
[Serializable]
public enum EventAttributes
[C++]
[Flags]
[Serializable]
__value public enum EventAttributes
[JScript]
public
Flags
Serializable
enum EventAttributes
解説
ビットごとの OR 演算を使用して複数の EventAttributes 値を組み合わせ、属性の適切な組み合わせを取得できます。
これらの列挙体はビットと列挙子の組み合わせで、corhdr.h ファイルで定義されています。
メンバ
メンバ名 | 説明 | 値 |
---|---|---|
None
.NET Compact Framework でもサポート。 |
イベントに属性がないことを指定します。 | 0 |
ReservedMask
.NET Compact Framework でもサポート。 |
共通言語ランタイム専用として予約済みのフラグを指定します。 | 1024 |
RTSpecialName
.NET Compact Framework でもサポート。 |
共通言語ランタイムが名前のエンコード方式をチェックする必要があることを指定します。 | 1024 |
SpecialName
.NET Compact Framework でもサポート。 |
イベントが特別であることを、名前で示すという方法で指定します。 | 512 |
使用例
Imports System
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit
Public Class MyApplication
Delegate Sub MyEvent(temp As Object)
Public Shared Sub Main()
Dim helloWorldClass As TypeBuilder = CreateCallee(Thread.GetDomain())
Dim info As EventInfo() = helloWorldClass.GetEvents(BindingFlags.Public Or _
BindingFlags.Instance)
Console.WriteLine("'HelloWorld' type has following events :")
Dim i As Integer
For i = 0 To info.Length - 1
Console.WriteLine(info(i).Name)
Next i
End Sub 'Main
' Create the callee transient dynamic assembly.
Private Shared Function CreateCallee(myDomain As AppDomain) As TypeBuilder
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = "EmittedAssembly"
' Create the callee dynamic assembly.
Dim myAssembly As AssemblyBuilder = myDomain.DefineDynamicAssembly _
(myAssemblyName, AssemblyBuilderAccess.Run)
' Create a dynamic module named "CalleeModule" in the callee
Dim myModule As ModuleBuilder = myAssembly.DefineDynamicModule("EmittedModule")
' Define a public class named "HelloWorld" in the assembly.
Dim helloWorldClass As TypeBuilder = myModule.DefineType _
("HelloWorld", TypeAttributes.Public)
Dim myMethod1 As MethodBuilder = helloWorldClass.DefineMethod _
("OnClick", MethodAttributes.Public, Nothing, New Type() {GetType(Object)})
Dim methodIL1 As ILGenerator = myMethod1.GetILGenerator()
methodIL1.Emit(OpCodes.Ret)
Dim myMethod2 As MethodBuilder = helloWorldClass.DefineMethod _
("OnMouseUp", MethodAttributes.Public, Nothing, New Type() {GetType(Object)})
Dim methodIL2 As ILGenerator = myMethod2.GetILGenerator()
methodIL2.Emit(OpCodes.Ret)
' Create the events.
Dim myEvent1 As EventBuilder = helloWorldClass.DefineEvent _
("Click", EventAttributes.None, GetType(MyEvent))
myEvent1.SetRaiseMethod(myMethod1)
Dim myEvent2 As EventBuilder = helloWorldClass.DefineEvent _
("MouseUp", EventAttributes.None, GetType(MyEvent))
myEvent2.SetRaiseMethod(myMethod2)
helloWorldClass.CreateType()
Return helloWorldClass
End Function 'CreateCallee
End Class 'MyApplication
[C#]
using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
public class MyApplication
{
public delegate void MyEvent(Object temp);
public static void Main()
{
TypeBuilder helloWorldClass = CreateCallee(Thread.GetDomain());
EventInfo[] info =
helloWorldClass.GetEvents(BindingFlags.Public | BindingFlags.Instance);
Console.WriteLine("'HelloWorld' type has following events :");
for(int i=0; i < info.Length; i++)
Console.WriteLine(info[i].Name);
}
// Create the callee transient dynamic assembly.
private static TypeBuilder CreateCallee(AppDomain myDomain)
{
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "EmittedAssembly";
// Create the callee dynamic assembly.
AssemblyBuilder myAssembly =
myDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
// Create a dynamic module named "CalleeModule" in the callee.
ModuleBuilder myModule = myAssembly.DefineDynamicModule("EmittedModule");
// Define a public class named "HelloWorld" in the assembly.
TypeBuilder helloWorldClass =
myModule.DefineType("HelloWorld", TypeAttributes.Public);
MethodBuilder myMethod1 = helloWorldClass.DefineMethod("OnClick",
MethodAttributes.Public, typeof(void), new Type[]{typeof(Object)});
ILGenerator methodIL1 = myMethod1.GetILGenerator();
methodIL1.Emit(OpCodes.Ret);
MethodBuilder myMethod2 = helloWorldClass.DefineMethod("OnMouseUp",
MethodAttributes.Public, typeof(void), new Type[]{typeof(Object)});
ILGenerator methodIL2 = myMethod2.GetILGenerator();
methodIL2.Emit(OpCodes.Ret);
// Create the events.
EventBuilder myEvent1 = helloWorldClass.DefineEvent("Click", EventAttributes.None,
typeof(MyEvent));
myEvent1.SetRaiseMethod(myMethod1);
EventBuilder myEvent2 = helloWorldClass.DefineEvent("MouseUp", EventAttributes.None,
typeof(MyEvent));
myEvent2.SetRaiseMethod(myMethod2);
helloWorldClass.CreateType();
return(helloWorldClass);
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Threading;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
__gc class MyApplication
{
private:
__delegate void MyEvent(Object* temp);
public:
// Create the callee transient dynamic assembly.
static TypeBuilder* CreateCallee(AppDomain* myDomain)
{
AssemblyName* assemblyName = new AssemblyName();
assemblyName->Name = S"EmittedAssembly";
// Create the callee dynamic assembly.
AssemblyBuilder* myAssembly = myDomain->DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess::Run);
// Create a dynamic module
ModuleBuilder* myModule = myAssembly->DefineDynamicModule(S"EmittedModule");
// Define a public class named "HelloWorld" in the assembly.
TypeBuilder* helloWorldClass = myModule->DefineType(S"HelloWorld", TypeAttributes::Public);
Type* typeArray __gc[] = new Type* __gc[1];
typeArray[0] = __typeof(Object);
MethodBuilder* myMethod1 = helloWorldClass->DefineMethod(S"OnClick", MethodAttributes::Public, __typeof(void), typeArray);
ILGenerator* methodIL1 = myMethod1->GetILGenerator();
methodIL1->Emit(OpCodes::Ret);
MethodBuilder* myMethod2 = helloWorldClass->DefineMethod(S"OnMouseUp", MethodAttributes::Public, __typeof(void), typeArray);
ILGenerator* methodIL2 = myMethod2->GetILGenerator();
methodIL2->Emit(OpCodes::Ret);
// Create the events.
EventBuilder* myEvent1 = helloWorldClass->DefineEvent(S"Click", EventAttributes::None,
__typeof(MyEvent));
myEvent1->SetRaiseMethod(myMethod1);
EventBuilder* myEvent2 = helloWorldClass->DefineEvent(S"MouseUp", EventAttributes::None,
__typeof(MyEvent));
myEvent2->SetRaiseMethod(myMethod2);
helloWorldClass->CreateType();
return(helloWorldClass);
}
};
int main()
{
TypeBuilder* helloWorldClass = MyApplication::CreateCallee(Thread::GetDomain());
EventInfo* info[] = helloWorldClass->GetEvents(static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance));
Console::WriteLine(S"'HelloWorld' type has following events :");
for (int i=0; i < info->Length; i++)
Console::WriteLine(info[i]->Name);
return 0;
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Reflection
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
アセンブリ: Mscorlib (Mscorlib.dll 内)