英語で読む

次の方法で共有


MethodBuilder.SetImplementationFlags(MethodImplAttributes) メソッド

定義

このメソッドの実装フラグを取得または設定します。

C#
public void SetImplementationFlags(System.Reflection.MethodImplAttributes attributes);

パラメーター

attributes
MethodImplAttributes

設定する実装フラグ。

例外

含まれている型は、CreateType() を使用して以前に作成されています。

- または -

現在のメソッドでは、IsGenericMethod プロパティは true ですが、IsGenericMethodDefinition プロパティは false です。

次のコード サンプルは、メソッド本体での MSIL の SetImplementationFlags 実装を記述するための メソッドのコンテキストでの使用を示しています。

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

注釈

メソッドと メソッドを SetImplementationFlags 組み合わせて使用する SetCustomAttribute 場合は、潜在的な相互作用に注意してください。 たとえば、 メソッドを SetCustomAttribute 使用して 属性を追加すると、 DllImportAttribute フラグも設定されます MethodImplAttributes.PreserveSig 。 その後、 メソッドを SetImplementationFlags 呼び出すと、 PreserveSig フラグが上書きされます。 この回避方法は次の 2 とおりあります。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1