Bagikan melalui


MethodBuilder.SetImplementationFlags(MethodImplAttributes) Metode

Definisi

Mengatur bendera implementasi untuk metode ini.

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)

Parameter

attributes
MethodImplAttributes

Bendera implementasi yang akan ditetapkan.

Pengecualian

Jenis yang berisi sebelumnya dibuat menggunakan CreateType().

-atau-

Untuk metode saat ini, IsGenericMethod properti adalah true, tetapi IsGenericMethodDefinition propertinya adalah false.

Contoh

Sampel kode di bawah ini menggambarkan penggunaan SetImplementationFlags kontekstual metode untuk menjelaskan implementasi MSIL dalam isi metode.

array<Type^>^ temp0 = { int::typeid, int::typeid };
MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "MyMethod",
                               MethodAttributes::Public,
                               CallingConventions::HasThis,
                               int::typeid,
                               temp0 );

// 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)(
                                        MethodImplAttributes::IL |
                                        MethodImplAttributes::Managed |
                                        MethodImplAttributes::Synchronized |
                                        MethodImplAttributes::NoInlining) );

// Create an ILGenerator for the MethodBuilder and emit MSIL here ...
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 ...

Keterangan

Ketika Anda menggunakan SetImplementationFlags metode dalam kombinasi dengan SetCustomAttribute metode , waspadai potensi interaksi. Misalnya, menggunakan SetCustomAttribute metode untuk menambahkan DllImportAttribute atribut juga mengatur MethodImplAttributes.PreserveSig bendera . Jika Anda kemudian memanggil SetImplementationFlags metode , bendera akan PreserveSig ditimpa. Ada dua cara untuk menghindari hal ini:

Berlaku untuk