MethodBuilder.SetImplementationFlags(MethodImplAttributes) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Anger implementeringsflaggor för den här metoden.
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)
Parametrar
- attributes
- MethodImplAttributes
De implementeringsflaggor som ska anges.
Undantag
Den innehållande typen skapades tidigare med .CreateType()
-eller-
För den aktuella metoden är IsGenericMethodegenskapen true , men egenskapen IsGenericMethodDefinition är false.
Exempel
Kodexemplet nedan illustrerar den kontextuella användningen av SetImplementationFlags metoden för att beskriva implementeringen av MSIL i en metodtext.
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 ...
Kommentarer
När du använder SetImplementationFlags metoden i kombination med SetCustomAttribute metoden bör du vara medveten om potentiella interaktioner. Om du till exempel använder SetCustomAttribute metoden för att lägga DllImportAttribute till attributet anges MethodImplAttributes.PreserveSig även flaggan. Om du senare anropar SetImplementationFlags metoden skrivs PreserveSig flaggan över. Det finns två sätt att undvika detta:
SetImplementationFlags Anropa metoden innan du anropar SetCustomAttribute metoden. Metoden SetCustomAttribute respekterar alltid befintliga metodimplementeringsflaggor.
När du anger implementeringsflaggor anropar GetMethodImplementationFlags du metoden för att hämta befintliga flaggor, använder bitvis ELLER för att lägga till flaggan och anropar SetImplementationFlags sedan metoden.