using Microsoft.Extensions.DependencyModel; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace Infrastructure.Helper { public static class AssemblyUtils { /// /// 获取应用中的所有程序集 /// /// public static IEnumerable GetAssemblies() { var compilationLibrary = DependencyContext.Default .CompileLibraries .Where(x => !x.Serviceable && x.Type == "project") .ToList(); return compilationLibrary.Select(p => Assembly.Load(new AssemblyName(p.Name))); } /// /// 获取应用中的所有Type /// /// public static IEnumerable GetAllTypes() { var assemblies = GetAssemblies(); return assemblies.SelectMany(p => p.GetTypes()); } } }