Export (0) Print
Expand All
Expand Minimize

EventAttributes Enumeration

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)

[SerializableAttribute] 
[FlagsAttribute] 
[ComVisibleAttribute(true)] 
public enum EventAttributes
/** @attribute SerializableAttribute() */ 
/** @attribute FlagsAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum EventAttributes
SerializableAttribute 
FlagsAttribute 
ComVisibleAttribute(true) 
public enum EventAttributes

 Member nameDescription
Supported by the .NET Compact FrameworkNoneSpecifies that the event has no attributes. 
Supported by the .NET Compact FrameworkReservedMaskSpecifies a reserved flag for common language runtime use only. 
Supported by the .NET Compact FrameworkRTSpecialNameSpecifies that the common language runtime should check name encoding. 
Supported by the .NET Compact FrameworkSpecialNameSpecifies that the event is special in a way described by the name. 

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

These enums are defined in the corhdr.h file and are a combination of bits and enumerators.

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


import System.*;
import System.Threading.*;
import System.Reflection.*;
import System.Reflection.Emit.*;

public class MyApplication
{
    /** @delegate 
     */
    public delegate void MyEvent(Object temp);

    public static void main(String[] args)
    {
        TypeBuilder helloWorldClass =
            CreateCallee(System.Threading.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].get_Name());
        }
    } //main

    // Create the callee transient dynamic assembly.
    private static TypeBuilder CreateCallee(AppDomain myDomain)
    {
        AssemblyName assemblyName = new AssemblyName();
        assemblyName.set_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, void.class.ToType(),
            new Type[] { Object.class.ToType() });
        ILGenerator methodIL1 = myMethod1.GetILGenerator();
        methodIL1.Emit(OpCodes.Ret);
        MethodBuilder myMethod2 = helloWorldClass.DefineMethod("OnMouseUp",
            MethodAttributes.Public, void.class.ToType(),
            new Type[] { Object.class.ToType() });
        ILGenerator methodIL2 = myMethod2.GetILGenerator();
        methodIL2.Emit(OpCodes.Ret);
        // Create the events.
        EventBuilder myEvent1 = helloWorldClass.DefineEvent("Click",
            EventAttributes.None, MyEvent.class.ToType());
        myEvent1.SetRaiseMethod(myMethod1);
        EventBuilder myEvent2 = helloWorldClass.DefineEvent("MouseUp",
            EventAttributes.None, MyEvent.class.ToType());
        myEvent2.SetRaiseMethod(myMethod2);

        helloWorldClass.CreateType();
        return helloWorldClass;
    } //CreateCallee
}//MyApplication

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft