MethodBuilder.SetImplementationFlags(MethodImplAttributes) Metoda

Definice

Nastaví příznaky implementace pro tuto metodu.

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)

Parametry

attributes
MethodImplAttributes

Příznaky implementace, které se mají nastavit.

Výjimky

Obsahující typ byl dříve vytvořen pomocí CreateType().

nebo

Pro aktuální metodu IsGenericMethod je truevlastnost , ale IsGenericMethodDefinition vlastnost je false.

Příklady

Následující ukázka kódu ilustruje kontextové použití SetImplementationFlags metody k popisu implementace jazyka MSIL v těle metody.

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 ...

Poznámky

Při použití SetImplementationFlags metody v kombinaci s metodou SetCustomAttribute mějte na paměti potenciální interakce. Například použití SetCustomAttribute metody k přidání atributu DllImportAttributeMethodImplAttributes.PreserveSig také nastaví příznak. Pokud následně zavoláte metodu SetImplementationFlags , PreserveSig příznak se přepíše. Existují dva způsoby, jak se tomu vyhnout:

Platí pro