static String GetDisplayName(IAssemblyName name, ASM_DISPLAY_FLAGS which) { uint bufferSize = 255; StringBuilder buffer = new StringBuilder((int)bufferSize); name.GetDisplayName(buffer, ref bufferSize, which); return(buffer.ToString()); }
/// <summary> /// 输出多行_主函数_内部. /// </summary> /// <param name="isfull">显示全部信息.</param> /// <param name="iw">带缩进输出者.</param> /// <param name="obj">object. Can be null.</param> /// <param name="context">State Object. Can be null.</param> /// <returns>返回是否成功输出.</returns> private static bool outl_main_core(bool isfull, IIndentedWriter iw, object obj, IndentedWriterContext context) { if (null == iw) { return(false); } ASM_DISPLAY_FLAGS flags = isfull ? ASM_DISPLAY_FLAGS.ASM_DISPLAYF_FULL : ASM_DISPLAY_FLAGS.ASM_DISPLAYF_RETARGET; //flags = ASM_DISPLAY_FLAGS.ASM_DISPLAYF_FULL; iw.WriteLine("# zinfoassemblylist"); foreach (string str in GacUtil.GacGetAssemblyNameList(flags, GacGetListOptions.AutoSort | GacGetListOptions.Fallback)) { iw.WriteLine(str); } return(true); }
public string GetDisplayName(ASM_DISPLAY_FLAGS flags) { int size = 0; _assemblyName.GetDisplayName(null, ref size, (uint)flags); if (size <= 0) { return(null); } var builder = new StringBuilder(size); _assemblyName.GetDisplayName(builder, ref size, (uint)flags); return(builder.ToString()); }
protected string getDisplayName(ASM_DISPLAY_FLAGS flags) { uint len = 0; int hr = _name.GetDisplayName(null, ref len, flags); if (hr == ComUtil.ERROR_INSUFFICIENT_BUFFER && len > 0) { StringBuilder displayName = new StringBuilder((int)len); ComUtil.ComCheck(_name.GetDisplayName(displayName, ref len, flags)); return(displayName.ToString()); } else { return(""); } }
/// <summary> /// Gets the display name. /// </summary> /// <param name="name">The name.</param> /// <param name="which">The which.</param> /// <returns></returns> public static String GetDisplayName(IAssemblyName name, ASM_DISPLAY_FLAGS which) { uint bufferSize = 255; var buffer = new StringBuilder((int) bufferSize); name.GetDisplayName(buffer, ref bufferSize, which); return buffer.ToString(); }
/// <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)); }
/// <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); }
/// <summary> /// 在GAC中枚举程序集名称. /// </summary> /// <param name="dwDisplayFlags">显示标志.</param> /// <returns>返回 <see cref="IEnumerable<String>"/>. </returns> /// <exception cref="global::System.DllNotFoundException">在mono等环境下有可能找不到dll.</exception> public static IEnumerable <String> GacEnumerateAssemblyName(ASM_DISPLAY_FLAGS dwDisplayFlags) { return(EnumerateAssemblyName(ASM_CACHE_FLAGS.ASM_CACHE_GAC, dwDisplayFlags)); }
/// <summary> /// 枚举程序集名称. /// </summary> /// <param name="dwCacheFlags">缓存标志.</param> /// <param name="dwDisplayFlags">显示标志.</param> /// <returns>返回 <see cref="IEnumerable<String>"/>. </returns> /// <exception cref="global::System.DllNotFoundException">在mono等环境下有可能找不到dll.</exception> public static IEnumerable <String> EnumerateAssemblyName(ASM_CACHE_FLAGS dwCacheFlags, ASM_DISPLAY_FLAGS dwDisplayFlags) { foreach (IAssemblyName asm in EnumerateIAssemblyName(dwCacheFlags)) { int ccbuf = DefaultStringBufferSize; StringBuilder sbuf = new StringBuilder(ccbuf); asm.GetDisplayName(sbuf, ref ccbuf, dwDisplayFlags); yield return(sbuf.ToString()); } }