MethodBuilder.SetImplementationFlags(MethodImplAttributes) 方法

定義

設定此方法的實作旗標。

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()

-或-

對於目前的方法,性質 IsGenericMethodtrue,但性質 IsGenericMethodDefinitionfalse

範例

以下程式碼範例說明了該方法在情境上的使用 SetImplementationFlags ,以描述 MSIL 在方法本體中的實作方式。

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

備註

當你將此方法與該方法結合SetCustomAttribute使用SetImplementationFlags時,請注意可能存在的互動。 例如,使用 SetCustomAttribute 該方法加入 DllImportAttribute 屬性也會設定 MethodImplAttributes.PreserveSig 該標誌。 如果你之後呼叫該 SetImplementationFlags 方法,該 PreserveSig 標記會被覆寫。 有兩種方法可以避免這種情況:

適用於