Description





Description

This enumeration is used by MethodImplAttribute.

Example

using System;

using System.Reflection;

using System.Runtime.CompilerServices;



/// <summary>

/// Sample demonstrating the use of the MethodImplOptions enumeration.

/// Use this enumeration to provide information about the implementation of 

/// methods decorated with MethodImplAttribute.

/// </summary>

internal class MethodImplOptionsSample

{



    private static void Main()

    {

        AppDomain domain = AppDomain.CreateDomain("Test domain 1");



        domain.DomainUnload += new EventHandler(Handler1);

        AppDomain.Unload(domain);



        domain = AppDomain.CreateDomain("Test domain 2");

        domain.DomainUnload += new EventHandler(Handler2);

        AppDomain.Unload(domain);



        Console.WriteLine();

        Console.WriteLine();

        Console.WriteLine("Press Enter to continue");

        Console.ReadLine();

    }



    // Must be public for serialization support.

    public static void Handler1(object sender, EventArgs e)

    {

        Console.WriteLine("The caller of GetCallingAssemblyName1() is:");

        Console.WriteLine(GetCallingAssemblyName1());

        Console.WriteLine();

    }



    // Returns the name of the calling assembly. The use of 

    // MethodImplOptions.NoInlining prevents the jitter from inlining the 

    // method.

    [MethodImpl(MethodImplOptions.NoInlining)]

    private static string GetCallingAssemblyName1()

    {

        return Assembly.GetCallingAssembly().FullName;

    }



    // Must be public for serialization support.

    public static void Handler2(object sender, EventArgs e)

    {

        Console.WriteLine("The caller of GetCallingAssemblyName2() is:");

        Console.WriteLine(GetCallingAssemblyName2());

        Console.WriteLine();

    }



    // Returns the name of the calling assembly. The jitter is free to inline 

    // this method. Note that inlining will only occur in release builds with 

    // no debugger attached, e.g. CTRL+F5.

    private static string GetCallingAssemblyName2()

    {

        return Assembly.GetCallingAssembly().FullName;

    }



}


The output is


The caller of GetCallingAssemblyName1() is:

MethodImplOptions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null



The caller of GetCallingAssemblyName2() is:

MethodImplOptions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null







Press Enter to continue



     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows