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。
示例
下面的代码示例演示了方法在 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 覆盖 标志。 可通过两种方式来避免此问题:
在 SetImplementationFlags 调用 方法之前调用 SetCustomAttribute 方法。 方法 SetCustomAttribute 始终遵循现有的方法实现标志。
设置实现标志时,请调用 GetMethodImplementationFlags 方法来检索现有标志,使用按位 OR 添加标志,然后调用 SetImplementationFlags 方法。