MethodBuilder.SetImplementationFlags(MethodImplAttributes) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Imposta i flag di implementazione per questo metodo.
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)
Parametri
- attributes
- MethodImplAttributes
Flag di implementazione da impostare.
Eccezioni
Il tipo contenitore è stato creato in precedenza usando CreateType().
oppure
Per il metodo corrente, la IsGenericMethod proprietà è true, ma la IsGenericMethodDefinition proprietà è false.
Esempio
L'esempio di codice seguente illustra l'uso contestuale del SetImplementationFlags metodo per descrivere l'implementazione di MSIL in un corpo del metodo.
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 ...
Commenti
Quando si usa il SetImplementationFlags metodo in combinazione con il SetCustomAttribute metodo , tenere presente le potenziali interazioni. Ad esempio, l'uso del SetCustomAttribute metodo per aggiungere l'attributo DllImportAttribute imposta anche il MethodImplAttributes.PreserveSig flag . Se successivamente si chiama il SetImplementationFlags metodo , il PreserveSig flag viene sovrascritto. Esistono due modi per evitare questo problema:
Chiamare il SetImplementationFlags metodo prima di chiamare il SetCustomAttribute metodo . Il SetCustomAttribute metodo rispetta sempre i flag di implementazione del metodo esistenti.
Quando si impostano i flag di implementazione, chiamare il GetMethodImplementationFlags metodo per recuperare i flag esistenti, usare OR bit per bit per aggiungere il flag e quindi chiamare il SetImplementationFlags metodo .