MethodBuilder.SetImplementationFlags(MethodImplAttributes) Méthode

Définition

Définit les indicateurs d’implémentation pour cette méthode.

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)

Paramètres

attributes
MethodImplAttributes

Indicateurs d’implémentation à définir.

Exceptions

Le type conteneur a été créé précédemment à l’aide CreateType()de .

- ou -

Pour la méthode actuelle, la IsGenericMethod propriété est true, mais la IsGenericMethodDefinition propriété est false.

Exemples

L’exemple de code ci-dessous illustre l’utilisation contextuelle de la SetImplementationFlags méthode pour décrire l’implémentation de MSIL dans un corps de méthode.

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

Remarques

Lorsque vous utilisez la SetImplementationFlags méthode en combinaison avec la SetCustomAttribute méthode, tenez compte des interactions potentielles. Par exemple, l’utilisation de la SetCustomAttribute méthode pour ajouter l’attribut DllImportAttribute définit également l’indicateur MethodImplAttributes.PreserveSig . Si vous appelez par la suite la SetImplementationFlags méthode, l’indicateur PreserveSig est remplacé. Il existe deux façons d’éviter cela :

S’applique à