MethodBuilder.SetImplementationFlags(MethodImplAttributes) Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
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.
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:
Llame al SetImplementationFlags método antes de llamar al SetCustomAttribute método . El SetCustomAttribute método siempre respeta las marcas de implementación de método existentes.
Al establecer marcas de implementación, llame al GetMethodImplementationFlags método para recuperar las marcas existentes, use OR bit a bit para agregar la marca y, a continuación, llame al SetImplementationFlags método .