Export (0) Print
Expand All

MethodBuilder.SetImplementationFlags Method

Sets the implementation flags for this method.

[Visual Basic]
Public Sub SetImplementationFlags( _
   ByVal attributes As MethodImplAttributes _
)
[C#]
public void SetImplementationFlags(
 MethodImplAttributes attributes
);
[C++]
public: void SetImplementationFlags(
 MethodImplAttributes attributes
);
[JScript]
public function SetImplementationFlags(
   attributes : MethodImplAttributes
);

Parameters

attributes
The implementation flags to set.

Exceptions

Exception Type Condition
InvalidOperationException The containing type was previously created using CreateType.

Example

[Visual Basic, C#, C++] The code sample below illustrates the contextual use of the SetImplementationFlags method to describe the implementation of MSIL in a method body.

[Visual Basic] 
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 ...

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


[C++] 
Type* temp0 [] = {__typeof(int), __typeof(int)};
MethodBuilder*  myMthdBuilder = myTypeBuilder->DefineMethod(
   S"MyMethod",
   MethodAttributes::Public,
   CallingConventions::HasThis,
   __typeof(int),
   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(
   static_cast<MethodImplAttributes>(MethodImplAttributes::IL |
   MethodImplAttributes::Managed |
   MethodImplAttributes::Synchronized |
   MethodImplAttributes::NoInlining));

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

MethodBuilder Class | MethodBuilder Members | System.Reflection.Emit Namespace

Show:
© 2014 Microsoft