MethodBuilder.SetImplementationFlags(MethodImplAttributes) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee stelt u de implementatievlagmen voor deze methode in.
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)
Parameters
- attributes
- MethodImplAttributes
De implementatievlagmen die moeten worden ingesteld.
Uitzonderingen
Het type dat het bevat, is eerder gemaakt met behulp van CreateType().
– of –
Voor de huidige methode is de IsGenericMethod eigenschap , maar de IsGenericMethodDefinition eigenschap is false.true
Voorbeelden
Het onderstaande codevoorbeeld illustreert het contextuele gebruik van de SetImplementationFlags methode om de implementatie van MSIL in een methodebody te beschrijven.
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 ...
Opmerkingen
Wanneer u de SetImplementationFlags methode in combinatie met de SetCustomAttribute methode gebruikt, moet u rekening houden met mogelijke interacties. Als u bijvoorbeeld de SetCustomAttribute methode gebruikt om het DllImportAttribute kenmerk toe te voegen, wordt ook de MethodImplAttributes.PreserveSig vlag ingesteld. Als u de SetImplementationFlags methode vervolgens aanroept, wordt de PreserveSig vlag overschreven. Er zijn twee manieren om dit te voorkomen:
Roep de SetImplementationFlags methode aan voordat u de SetCustomAttribute methode aanroept. De SetCustomAttribute methode respecteert altijd bestaande vlaggen voor de implementatie van methoden.
Wanneer u implementatievlagmen instelt, roept u de GetMethodImplementationFlags methode aan om de bestaande vlaggen op te halen, gebruikt u bitwise OR om uw vlag toe te voegen en roept u de SetImplementationFlags methode aan.