當前位置: 首頁>>代碼示例>>C#>>正文


C# AssemblyFlagsAttribute構造函數代碼示例

本文整理匯總了C#中System.Reflection.AssemblyFlagsAttribute.AssemblyFlagsAttribute構造函數的典型用法代碼示例。如果您正苦於以下問題:C# AssemblyFlagsAttribute構造函數的具體用法?C# AssemblyFlagsAttribute怎麽用?C# AssemblyFlagsAttribute使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在System.Reflection.AssemblyFlagsAttribute的用法示例。


在下文中一共展示了AssemblyFlagsAttribute構造函數的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

//引入命名空間
using System;
using System.Reflection;

// Specify a combination of AssemblyNameFlags for this 
// assembly.
[assembly:AssemblyFlagsAttribute(
    AssemblyNameFlags.EnableJITcompileOptimizer |
    AssemblyNameFlags.Retargetable)]

public class Example
{
    public static void Main()
    {
        // Get this assembly.
        Assembly thisAsm = typeof(Example).Assembly;

        // Get the AssemblyName for this assembly.
        AssemblyName thisAsmName = thisAsm.GetName(false);

        // Display the flags that were set for this assembly.
        ListFlags(thisAsmName.Flags);

        // Create an instance of AssemblyFlagsAttribute with the
        // same combination of flags that was specified for this
        // assembly. Note that PublicKey is included automatically
        // for the assembly, but not for this instance of
        // AssemblyFlagsAttribute.
        AssemblyFlagsAttribute afa = new AssemblyFlagsAttribute(
            AssemblyNameFlags.EnableJITcompileOptimizer |
            AssemblyNameFlags.Retargetable);

        // Get the flags. The property returns an integer, so
        // the return value must be cast to AssemblyNameFlags.
        AssemblyNameFlags anf = (AssemblyNameFlags) afa.AssemblyFlags;

        // Display the flags.
        Console.WriteLine();
        ListFlags(anf);
    }

    private static void ListFlags(AssemblyNameFlags anf)
    {
        if (anf == AssemblyNameFlags.None)
        {
            Console.WriteLine("AssemblyNameFlags.None");
        }
        else
        {
            if (0!=(anf & AssemblyNameFlags.Retargetable)) 
                Console.WriteLine("AssemblyNameFlags.Retargetable");
            if (0!=(anf & AssemblyNameFlags.PublicKey)) 
                Console.WriteLine("AssemblyNameFlags.PublicKey");
            if (0!=(anf & AssemblyNameFlags.EnableJITcompileOptimizer)) 
                Console.WriteLine("AssemblyNameFlags.EnableJITcompileOptimizer");
            if (0!=(anf & AssemblyNameFlags.EnableJITcompileTracking)) 
                Console.WriteLine("AssemblyNameFlags.EnableJITcompileTracking");
        }
    }
}
開發者ID:.NET開發者,項目名稱:System.Reflection,代碼行數:60,代碼來源:AssemblyFlagsAttribute

輸出:

AssemblyNameFlags.Retargetable
AssemblyNameFlags.PublicKey
AssemblyNameFlags.EnableJITcompileOptimizer

AssemblyNameFlags.Retargetable
AssemblyNameFlags.EnableJITcompileOptimizer


注:本文中的System.Reflection.AssemblyFlagsAttribute.AssemblyFlagsAttribute構造函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。