Ejemplo n.º 1
0
 private static extern void CreateAssemblyEnum(out IAssemblyEnum pEnum, IntPtr pUnkReserved, IAssemblyName pName,
     ASM_CACHE_FLAGS dwFlags, IntPtr pvReserved);
Ejemplo n.º 2
0
 private static extern void GetCachePath(ASM_CACHE_FLAGS dwCacheFlags,
     [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwzCachePath,
     ref uint pcchPath);
Ejemplo n.º 3
0
 static extern int GetCachePath(ASM_CACHE_FLAGS dwCacheFlags, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwzCachePath, ref uint pcchPath);
Ejemplo n.º 4
0
 static extern void CreateAssemblyEnum(out IAssemblyEnum pEnum, IntPtr pUnkReserved, IAssemblyName pName,
                                       ASM_CACHE_FLAGS dwFlags, IntPtr pvReserved);
Ejemplo n.º 5
0
 public static extern int CreateAssemblyEnum(
     out IAssemblyEnum ppEnum,
     IntPtr pUnkReserved,
     IAssemblyName pName,
     ASM_CACHE_FLAGS flags,
     IntPtr pvReserved);
Ejemplo n.º 6
0
 static string GetCachePath(ASM_CACHE_FLAGS flags)
 {
     var sb = new StringBuilder(0x400);
     uint len = (uint)sb.Capacity;
     int hr = GetCachePath(flags, sb, ref len);
     Debug.Assert(hr == 0);
     if (hr != 0)
         return string.Empty;
     return sb.ToString();
 }
 public static extern int CreateAssemblyEnum(
     out IAssemblyEnum ppEnum,                 // Pointer to a memory location that contains the IAssemblyEnum pointer
     IApplicationContext pAppCtx,              // Must be null. ???
     IAssemblyName pName,                      // An assembly name that is used to filter the enumeration. Can be null to enumerate all assemblies in the GAC.
     ASM_CACHE_FLAGS dwFlags,                  // Exactly one bit from the ASM_CACHE_FLAGS enumeration.
     int pvReserved);                          // Must be NULL
Ejemplo n.º 8
0
 public static extern int CreateAssemblyEnum(
     out IAssemblyEnum ppEnum,
     IntPtr pUnkReserved,
     IAssemblyName pName,
     ASM_CACHE_FLAGS flags,
     IntPtr pvReserved);
Ejemplo n.º 9
0
        /// <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);
        }