コード例 #1
0
ファイル: GacUtil.cs プロジェクト: zyl910/ZylLib.NET
 /// <summary>
 /// 在Gac中取得程序集名称列表.
 /// </summary>
 /// <param name="dwDisplayFlags">显示标志.</param>
 /// <param name="listoptions">列表选项.</param>
 /// <returns>返回程序集名称列表.</returns>
 /// <exception cref="global::System.DllNotFoundException">在mono等环境下有可能找不到dll.</exception>
 public static List <String> GacGetAssemblyNameList(ASM_DISPLAY_FLAGS dwDisplayFlags, GacGetListOptions listoptions)
 {
     return(GetAssemblyNameList(ASM_CACHE_FLAGS.ASM_CACHE_GAC, dwDisplayFlags, listoptions));
 }
コード例 #2
0
ファイル: GacUtil.cs プロジェクト: zyl910/ZylLib.NET
        /// <summary>
        /// 取得程序集名称列表.
        /// </summary>
        /// <param name="dwCacheFlags">缓存标志.</param>
        /// <param name="dwDisplayFlags">显示标志.</param>
        /// <param name="listoptions">列表选项.</param>
        /// <returns>返回程序集名称列表.</returns>
        /// <exception cref="global::System.DllNotFoundException">当 <paramref name="listoptions"/> 没有 <see cref="GacGetListOptions.Fallback"/> 标志时 , 在mono等环境下有可能找不到dll.</exception>
        public static List <String> GetAssemblyNameList(ASM_CACHE_FLAGS dwCacheFlags, ASM_DISPLAY_FLAGS dwDisplayFlags, GacGetListOptions listoptions)
        {
            List <String> lst = new List <string>();
            // get list.
            bool isok = false;

#if (!PORTABLE)
            try {
                foreach (string str in EnumerateAssemblyName(dwCacheFlags, dwDisplayFlags))
                {
                    lst.Add(str);
                }
                isok = true;
            }
            catch {
                if (0 == (listoptions & GacGetListOptions.Fallback))
                {
                    // 没有标识, 重抛异常.
                    throw;
                }
                else
                {
                    // 忽略.
                }
            }
#endif
            if (0 != (listoptions & GacGetListOptions.Fallback) && dwCacheFlags == ASM_CACHE_FLAGS.ASM_CACHE_GAC)
            {
                // 尝试枚举当前应用程序域.
#if (!NETFX_CORE && !PORTABLE)
                if (!isok && lst.Count == 0)
                {
                    try {
                        foreach (Assembly p in AppDomain.CurrentDomain.GetAssemblies())
                        {
                            lst.Add(p.FullName);
                        }
                        isok = true;
                    }
                    catch {
                        // 忽略.
                    }
                }
#endif
                // 尝试所在程序集.
                if (!isok && lst.Count == 0)
                {
                    Type tp = typeof(GacUtil);
#if (NETFX_CORE)
                    TypeInfo ti = tp.GetTypeInfo();
                    lst.Add(ti.Assembly.FullName);
                    isok = true;
#else
                    lst.Add(tp.Assembly.FullName);
                    isok = true;
#endif
                }
            }
            // sort.
            if (0 != (listoptions & GacGetListOptions.AutoSort))
            {
                lst.Sort(StringComparer.OrdinalIgnoreCase);
            }
            return(lst);
        }