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

要设置的实现标志。

例外

以前使用 创建包含类型。

-或-

对于当前方法,该 IsGenericMethod 属性为 true,但属性 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 ...

注解

SetImplementationFlags 该方法与 SetCustomAttribute 该方法结合使用时,请注意潜在的交互。 例如,使用 SetCustomAttribute 该方法添加 DllImportAttribute 属性也会设置 MethodImplAttributes.PreserveSig 标志。 如果随后调用该方法 SetImplementationFlags ,则会 PreserveSig 覆盖该标志。 有两种方法可以避免这种情况:

适用于