MethodBuilder.SetImplementationFlags(MethodImplAttributes) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
このメソッドの実装フラグを設定します。
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
設定する実装フラグ。
例外
包含型は、以前に CreateType() を使用して作成されました。
-または-
現在のメソッドの場合、 IsGenericMethod プロパティは trueされますが、 IsGenericMethodDefinition プロパティは false。
例
次のコード サンプルは、メソッド本体での MSIL の実装を記述する SetImplementationFlags メソッドのコンテキストでの使用を示しています。
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メソッドと組み合わせて使用する場合は、潜在的な相互作用に注意してください。 たとえば、 SetCustomAttribute メソッドを使用して DllImportAttribute 属性を追加すると、 MethodImplAttributes.PreserveSig フラグも設定されます。 その後、 SetImplementationFlags メソッドを呼び出すと、 PreserveSig フラグが上書きされます。 これを回避するには、次の 2 つの方法があります。
SetCustomAttribute メソッドを呼び出す前に、SetImplementationFlags メソッドを呼び出します。 SetCustomAttribute メソッドは、常に既存のメソッド実装フラグを考慮します。
実装フラグを設定するときは、 GetMethodImplementationFlags メソッドを呼び出して既存のフラグを取得し、ビットごとの OR を使用してフラグを追加してから、 SetImplementationFlags メソッドを呼び出します。