MethodBuilder.SetImplementationFlags(MethodImplAttributes) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Beállítja a metódus implementálási jelzőit.
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éterek
- attributes
- MethodImplAttributes
A beállítandó implementációs jelzők.
Kivételek
A tartalmazó típus korábban a következővel lett létrehozva CreateType(): .
-vagy-
Az aktuális metódus esetében a IsGenericMethod tulajdonság az true, de a IsGenericMethodDefinition tulajdonság az false.
Példák
Az alábbi kódminta a metódus környezetfüggő használatát SetImplementationFlags mutatja be az MSIL implementációjának leírására egy metódustörzsben.
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 ...
Megjegyzések
Ha a SetImplementationFlags metódust a metódussal kombinálva használja, vegye figyelembe a SetCustomAttribute lehetséges interakciókat. Az attribútum hozzáadására szolgáló metódussal SetCustomAttribute például a jelölőt is beállítjaDllImportAttribute.MethodImplAttributes.PreserveSig Ha később meghívja a metódust SetImplementationFlags , a PreserveSig jelölő felülíródik. Ezt kétféleképpen lehet elkerülni:
A metódus meghívása SetImplementationFlags előtt hívja meg a metódust SetCustomAttribute . A SetCustomAttribute metódus mindig tiszteletben tartja a meglévő metódus-implementálási jelzőket.
A megvalósítási jelzők beállításakor hívja meg a metódust a GetMethodImplementationFlags meglévő jelzők lekéréséhez, a bitenkénti vagy a jelölő hozzáadásához, majd hívja meg a metódust SetImplementationFlags .