using System.Reflection;

namespace ServiceCenter.Extensions
{
    /// <summary>
    /// 针对程序集操作的扩展
    /// </summary>
    public static class AssemblyExtension
    {
        /// <summary>
        /// 删除重复的程序集
        /// </summary>
        /// <param name="assemblies"></param>
        public static IEnumerable<Assembly> RemoveDuplicateAssemblies(this IEnumerable<Assembly> assemblies)
        {
            return assemblies.DistinctBy(p => p.FullName);
        }

        /// <summary>
        /// 删除指定名称的程序集
        /// </summary>
        /// <param name="assemblyNames"></param>
        /// <returns></returns>
        public static IEnumerable<AssemblyName> RemoveTheAssemblyNamespecified(this IEnumerable<AssemblyName> assemblyNames)
        {
            return assemblyNames.Where(p => p.Name != null && !p.Name.StartsWith("System."))
                .Where(p => !p.Name.StartsWith("mscorlib."))
                .Where(p => !p.Name.StartsWith("netstandard."))
                .Where(p => !p.Name.StartsWith("Senparc."))
                .Where(p => !p.Name.StartsWith("Newtonsoft."))
                .Where(p => !p.Name.StartsWith("UnityEngine."))
                .Where(p => !p.Name.StartsWith("ZKWeb."))
                .Where(p => !p.Name.StartsWith("NPOI."))
                .Where(p => !p.Name.StartsWith("ICSharpCode."))
                .Where(p => !p.Name.StartsWith("NLog"))
                .Where(p => !p.Name.StartsWith("e_sqlite"))
                .Where(p => !p.Name.StartsWith("MsgPack."))
                .Where(p => !p.Name.StartsWith("netstandard"))
                .Where(p => !p.Name.StartsWith("Jiguang"))
                .Where(p => !p.Name.StartsWith("StackExchange"))
                .Where(p => !p.Name.StartsWith("Microsoft."))
                .Where(p => !p.Name.StartsWith("TIBCO."));
        }
    }
}
