MethodBuilder.SetImplementationFlags(MethodImplAttributes) メソッド

定義

このメソッドの実装フラグを取得または設定します。Sets the implementation flags for this method.

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)

パラメーター

attributes
MethodImplAttributes

設定する実装フラグ。The implementation flags to set.

例外

含まれている型は、CreateType() を使用して以前に作成されています。The containing type was previously created using CreateType().

または-or- 現在のメソッドでは、IsGenericMethod プロパティは true ですが、IsGenericMethodDefinition プロパティは false です。For the current method, the IsGenericMethod property is true, but the IsGenericMethodDefinition property is false.

次のコードサンプルでは、メソッド本体での MSIL の実装を記述するための SetImplementationFlags メソッドのコンテキスト使用法を示します。The code sample below illustrates the contextual use of the SetImplementationFlags method to describe the implementation of MSIL in a method body.

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 ...

注釈

SetImplementationFlags メソッドを SetCustomAttribute メソッドと組み合わせて使用する場合は、潜在的な相互作用に注意してください。When you use the SetImplementationFlags method in combination with the SetCustomAttribute method, be aware of potential interactions. たとえば、SetCustomAttribute メソッドを使用して DllImportAttribute 属性を追加すると、MethodImplAttributes.PreserveSig フラグも設定されます。For example, using the SetCustomAttribute method to add the DllImportAttribute attribute also sets the MethodImplAttributes.PreserveSig flag. その後 SetImplementationFlags メソッドを呼び出すと、PreserveSig フラグが上書きされます。If you subsequently call the SetImplementationFlags method, the PreserveSig flag is overwritten. これを回避するには、次の 2 つの方法があります。There are two ways to avoid this:

適用対象