EventAttributes 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定事件的屬性。
此列舉支援其成員值的位元組合。
public enum class EventAttributes
[System.Flags]
public enum EventAttributes
[System.Flags]
[System.Serializable]
public enum EventAttributes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum EventAttributes
[<System.Flags>]
type EventAttributes =
[<System.Flags>]
[<System.Serializable>]
type EventAttributes =
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type EventAttributes =
Public Enum EventAttributes
- 繼承
- 屬性
欄位
None | 0 | 指定事件沒有屬性。 |
ReservedMask | 1024 | 指定保留的旗標僅供 Common Language Runtime 使用。 |
RTSpecialName | 1024 | 指定 Common Language Runtime 應該檢查名稱編碼方式。 |
SpecialName | 512 | 指定由名稱所描述事件的特殊性。 |
範例
下列範例使用反映發出來建立具有兩個事件的型別。 它會使用 None 來指定事件沒有屬性。
using namespace System;
using namespace System::Threading;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
ref class MyApplication
{
private:
delegate void MyEvent( Object^ temp );
public:
// Create the callee transient dynamic assembly.
static TypeBuilder^ CreateCallee( AppDomain^ myDomain )
{
AssemblyName^ assemblyName = gcnew AssemblyName;
assemblyName->Name = "EmittedAssembly";
// Create the callee dynamic assembly.
AssemblyBuilder^ myAssembly = myDomain->DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess::Run );
// Create a dynamic module
ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule" );
// Define a public class named "HelloWorld" in the assembly.
TypeBuilder^ helloWorldClass = myModule->DefineType( "HelloWorld", TypeAttributes::Public );
array<Type^>^typeArray = gcnew array<Type^>(1);
typeArray[ 0 ] = Object::typeid;
MethodBuilder^ myMethod1 = helloWorldClass->DefineMethod( "OnClick", MethodAttributes::Public, void::typeid, typeArray );
ILGenerator^ methodIL1 = myMethod1->GetILGenerator();
methodIL1->Emit( OpCodes::Ret );
MethodBuilder^ myMethod2 = helloWorldClass->DefineMethod( "OnMouseUp", MethodAttributes::Public, void::typeid, typeArray );
ILGenerator^ methodIL2 = myMethod2->GetILGenerator();
methodIL2->Emit( OpCodes::Ret );
// Create the events.
EventBuilder^ myEvent1 = helloWorldClass->DefineEvent( "Click", EventAttributes::None, MyEvent::typeid );
myEvent1->SetRaiseMethod( myMethod1 );
EventBuilder^ myEvent2 = helloWorldClass->DefineEvent( "MouseUp", EventAttributes::None, MyEvent::typeid );
myEvent2->SetRaiseMethod( myMethod2 );
helloWorldClass->CreateType();
return (helloWorldClass);
}
};
int main()
{
TypeBuilder^ helloWorldClass = MyApplication::CreateCallee( Thread::GetDomain() );
array<EventInfo^>^info = helloWorldClass->GetEvents( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance) );
Console::WriteLine( "'HelloWorld' type has following events :" );
for ( int i = 0; i < info->Length; i++ )
Console::WriteLine( info[ i ]->Name );
return 0;
}
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);
}
}
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
' 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
備註
EventAttributes
值可以使用位 OR 運算來合併,以取得適當的組合。
這些列舉定義於 corhdr.h 檔案中,而且是位和列舉值的組合。