MethodBuilder.SetImplementationFlags(MethodImplAttributes) Método

Definición

Establece las marcas de implementación para este método.

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)

Parámetros

attributes
MethodImplAttributes

Marcas de implementación para establecer.

Excepciones

El tipo contenedor se creó anteriormente mediante CreateType().

o bien

Para el método actual, la propiedad IsGenericMethod es true, pero la propiedad IsGenericMethodDefinition es false.

Ejemplos

En el ejemplo de código siguiente se muestra el uso contextual del SetImplementationFlags método para describir la implementación de MSIL en un cuerpo del método.

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

Comentarios

Cuando use el SetImplementationFlags método en combinación con el SetCustomAttribute método , tenga en cuenta las posibles interacciones. Por ejemplo, el uso del SetCustomAttribute método para agregar el DllImportAttribute atributo también establece la MethodImplAttributes.PreserveSig marca . Si posteriormente llama al SetImplementationFlags método , se sobrescribe la PreserveSig marca. Existen dos formas de evitarlo:

Se aplica a