EventAttributes Wyliczenie

Definicja

Określa atrybuty zdarzenia.

To wyliczenie obsługuje bitową kombinację jego wartości składowych.

C#
[System.Flags]
public enum EventAttributes
C#
[System.Flags]
[System.Serializable]
public enum EventAttributes
C#
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum EventAttributes
Dziedziczenie
EventAttributes
Atrybuty

Pola

Nazwa Wartość Opis
None 0

Określa, że zdarzenie nie ma atrybutów.

ReservedMask 1024

Określa flagę zarezerwowaną tylko dla środowiska uruchomieniowego języka wspólnego.

RTSpecialName 1024

Określa, że środowisko uruchomieniowe języka wspólnego powinno sprawdzić kodowanie nazw.

SpecialName 512

Określa, że zdarzenie jest specjalne w sposób opisany przez nazwę.

Przykłady

W poniższym przykładzie użyto emisji odbicia w celu utworzenia typu z dwoma zdarzeniami. Używa metody None, aby określić, że zdarzenia nie mają atrybutów.

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

Uwagi

EventAttributes wartości mogą być łączone przy użyciu operacji bitowej OR w celu uzyskania odpowiedniej kombinacji.

Te wyliczenia są definiowane w pliku corhdr.h i są kombinacją bitów i wyliczeń.

Dotyczy

Produkt Wersje
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0