Прочетете на английски Редактиране

Споделяне чрез


MethodBuilder.SetImplementationFlags(MethodImplAttributes) Method

Definition

Sets the implementation flags for this method.

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

Parameters

attributes
MethodImplAttributes

The implementation flags to set.

Exceptions

The containing type was previously created using CreateType().

-or-

For the current method, the IsGenericMethod property is true, but the IsGenericMethodDefinition property is false.

Examples

The code sample below illustrates the contextual use of the SetImplementationFlags method to describe the implementation of MSIL in a method body.

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

Remarks

When you use the SetImplementationFlags method in combination with the SetCustomAttribute method, be aware of potential interactions. For example, using the SetCustomAttribute method to add the DllImportAttribute attribute also sets the MethodImplAttributes.PreserveSig flag. If you subsequently call the SetImplementationFlags method, the PreserveSig flag is overwritten. There are two ways to avoid this:

Applies to

Продукт Версии
.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