MethodBuilder.SetImplementationFlags(MethodImplAttributes) Methode

Definition

Legt die Implementierungskennzeichnungen für diese Methode fest.

public:
 void SetImplementationFlags(System::Reflection::MethodImplAttributes attributes);
public void SetImplementationFlags(System.Reflection.MethodImplAttributes attributes);
member this.SetImplementationFlags : System.Reflection.MethodImplAttributes -> unit
Public Sub SetImplementationFlags (attributes As MethodImplAttributes)

Parameter

attributes
MethodImplAttributes

Die festzulegenden Implementierungskennzeichnungen.

Ausnahmen

Der enthaltende Typ wurde zuvor mit CreateType().

-oder-

Für die aktuelle Methode ist die IsGenericMethod Eigenschaft , aber die IsGenericMethodDefinition Eigenschaft ist false.true

Beispiele

Das folgende Codebeispiel veranschaulicht die kontextbezogene Verwendung der SetImplementationFlags Methode zur Beschreibung der Implementierung von MSIL in einem Methodentext.

MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("MyMethod",
                    MethodAttributes.Public,
                    CallingConventions.HasThis,
                    typeof(int),
                    new Type[] { typeof(int),
                             typeof(int) });	

// Specifies that the dynamic method declared above has a an MSIL implementation,
    // is managed, synchronized (single-threaded) through the body, and that it
// cannot be inlined.

myMthdBuilder.SetImplementationFlags(MethodImplAttributes.IL |
                     MethodImplAttributes.Managed |
                     MethodImplAttributes.Synchronized |
                     MethodImplAttributes.NoInlining);

// Create an ILGenerator for the MethodBuilder and emit MSIL here ...
Dim myMthdBuilder As MethodBuilder = myTypeBuilder.DefineMethod("MyMethod", _
                 MethodAttributes.Public, _
                 CallingConventions.HasThis, _
                 GetType(Integer), _
                 New Type() {GetType(Integer), GetType(Integer)})

' Specifies that the dynamic method declared above has a an MSIL implementation,
' is managed, synchronized (single-threaded) through the body, and that it 
' cannot be inlined.

myMthdBuilder.SetImplementationFlags((MethodImplAttributes.IL Or _
                  MethodImplAttributes.Managed Or _
                  MethodImplAttributes.Synchronized Or _
                  MethodImplAttributes.NoInlining))

' Create an ILGenerator for the MethodBuilder and emit MSIL here ...

Hinweise

Wenn Sie die SetImplementationFlags Methode in Kombination mit der SetCustomAttribute Methode verwenden, beachten Sie potenzielle Interaktionen. Mit der SetCustomAttribute Methode zum Hinzufügen des DllImportAttribute Attributs wird beispielsweise auch das MethodImplAttributes.PreserveSig Flag festgelegt. Wenn Sie die SetImplementationFlags Methode anschließend aufrufen, wird das PreserveSig Flag überschrieben. Es gibt zwei Möglichkeiten, dies zu vermeiden:

Gilt für: