MethodBuilder.SetImplementationFlags(MethodImplAttributes) Metoda

Definicja

Ustawia flagi implementacji dla tej metody.

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

Flagi implementacji do ustawienia.

Wyjątki

Typ zawierający został wcześniej utworzony przy użyciu polecenia CreateType().

-lub-

Dla bieżącej metody IsGenericMethod właściwość to true, ale IsGenericMethodDefinition właściwość to false.

Przykłady

Poniższy przykład kodu ilustruje kontekstowe użycie SetImplementationFlags metody do opisania implementacji MSIL w treści metody.

array<Type^>^ temp0 = { int::typeid, int::typeid };
MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "MyMethod",
                               MethodAttributes::Public,
                               CallingConventions::HasThis,
                               int::typeid,
                               temp0 );

// 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)(
                                        MethodImplAttributes::IL |
                                        MethodImplAttributes::Managed |
                                        MethodImplAttributes::Synchronized |
                                        MethodImplAttributes::NoInlining) );

// Create an ILGenerator for the MethodBuilder and emit MSIL here ...
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 ...

Uwagi

Jeśli używasz metody w połączeniu SetImplementationFlagsSetCustomAttribute z metodą, należy pamiętać o potencjalnych interakcjach. Na przykład użycie metody w celu dodania SetCustomAttribute atrybutu DllImportAttribute powoduje również ustawienie flagi MethodImplAttributes.PreserveSig . Jeśli następnie wywołasz metodę, flaga SetImplementationFlagsPreserveSig zostanie zastąpiona. Istnieją dwa sposoby, aby tego uniknąć:

Dotyczy