MethodBuilder.SetImplementationFlags Method (MethodImplAttributes)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Sets the implementation flags for this method.

Namespace:   System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

member SetImplementationFlags : 
        attributes:MethodImplAttributes -> unit


Type: System.Reflection.MethodImplAttributes

The implementation flags to set.

Exception Condition

The containing type was previously created using CreateType.


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

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:

  • Call the SetImplementationFlags method before you call the SetCustomAttribute method. The SetCustomAttribute method always respects existing method implementation flags.

  • When you set implementation flags, call the GetMethodImplementationFlags method to retrieve the existing flags, use bitwise OR to add your flag, and then call the SetImplementationFlags method.

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

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Available since 2.0
Return to top