This documentation is archived and is not being maintained.

MethodBuilder::SetImplementationFlags Method

Sets the implementation flags for this method.

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

void SetImplementationFlags(
	MethodImplAttributes attributes


Type: System.Reflection::MethodImplAttributes
The implementation flags to set.


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.

array<Type^>^ temp0 = { int::typeid, int::typeid };
MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "MyMethod",
                               temp0 );

// 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)(
                                        MethodImplAttributes::IL |
                                        MethodImplAttributes::Managed |
                                        MethodImplAttributes::Synchronized |
                                        MethodImplAttributes::NoInlining) );

// Create an ILGenerator for the MethodBuilder and emit MSIL here ...

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.