This documentation is archived and is not being maintained.

MethodImplAttribute Class

Updated: September 2010

Specifies the details of how a method is implemented. This class cannot be inherited.

Namespace:  System.Runtime.CompilerServices
Assembly:  mscorlib (in mscorlib.dll)

[SerializableAttribute]
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets::Constructor|AttributeTargets::Method, Inherited = false)]
public ref class MethodImplAttribute sealed : public Attribute

You can apply this attribute to methods or constructors.

This attribute lets you customize the configuration of the method or constructor to which it applies. The members of the MethodImplOptions enumeration correspond to bit fields in the CorMethodImpl metadata table. This means that information on the attribute cannot be retrieved at run time by calling the MemberInfo::GetCustomAttributes method; instead, it is retrieved by calling either the MethodInfo.GetMethodImplementationFlags or the ConstructorInfo.GetMethodImplementationFlags method.

The following example applies the MethodImplAttribute to the GetCalendarName method to ensure that it is not inlined at run time by the just-in-time (JIT) compiler.

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

The following example then calls the MethodInfo.GetMethodImplementationFlags method to determine which flags are set for the GetCalendarName method. It also demonstrates that this information is not retrieved by the MemberInfo.GetCustomAttributes(System.Boolean) method.

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

System::Object
  System::Attribute
    System.Runtime.CompilerServices::MethodImplAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

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

.NET Framework

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

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Date

History

Reason

September 2010

Revised extensively.

Customer feedback.

Show: