This documentation is archived and is not being maintained.
EventAttributes Enumeration
Visual Studio 2010
Specifies the attributes of an event.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
Namespace: System.ReflectionAssembly: mscorlib (in mscorlib.dll)
| Member name | Description | |
|---|---|---|
![]() | None | Specifies that the event has no attributes. |
![]() | SpecialName | Specifies that the event is special in a way described by the name. |
![]() | ReservedMask | Specifies a reserved flag for common language runtime use only. |
![]() | RTSpecialName | Specifies that the common language runtime should check name encoding. |
The following example uses reflection emit to create a type with two events. It uses EventAttributes::None to specify that the events have no attributes.
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; }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show:
