EventAttributes Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Specifies the attributes of an event.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
<FlagsAttribute> _
Public Enumeration EventAttributes
[ComVisibleAttribute(true)]
[FlagsAttribute]
public enum EventAttributes

Members

Member name Description
Supported by Silverlight for Windows PhoneSupported by Xbox 360 None Specifies that the event has no attributes.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 SpecialName Specifies that the event is special in a way described by the name.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 ReservedMask Specifies a reserved flag for common language runtime use only.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 RTSpecialName Specifies that the common language runtime should check name encoding.

Remarks

EventAttributes values may be combined using the bitwise OR operation to get the appropriate combination.

Examples

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.

Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit

Public Class Example

   Delegate Sub MyEvent(ByVal temp As Object)

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim helloWorldClass As TypeBuilder = CreateCallee(Thread.GetDomain())

      Dim info As EventInfo() = helloWorldClass.GetEvents(BindingFlags.Public Or _
                                                          BindingFlags.Instance)
      outputBlock.Text &= "'HelloWorld' type has following events :" & vbCrLf
      Dim i As Integer
      For i = 0 To info.Length - 1
         outputBlock.Text &= info(i).Name & vbCrLf
      Next i
   End Sub 'Main

   ' Create the callee transient dynamic assembly.
   Private Shared Function CreateCallee(ByVal 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
using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;


public class Example
{
   public delegate void MyEvent(Object temp);
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      TypeBuilder helloWorldClass = CreateCallee(Thread.GetDomain());

      EventInfo[] info =
         helloWorldClass.GetEvents(BindingFlags.Public | BindingFlags.Instance);
      outputBlock.Text += "'HelloWorld' type has following events :" + "\n";
      for (int i = 0; i < info.Length; i++)
         outputBlock.Text += info[i].Name + "\n";
   }

   // 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);
   }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference