支持表自动迁移 & 优化ServiceProvider获取 & 包版本升级
This commit is contained in:
36
Infrastructure/Helper/AssemblyUtils.cs
Normal file
36
Infrastructure/Helper/AssemblyUtils.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取应用中的所有程序集
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Assembly> GetAssemblies()
|
||||
{
|
||||
var compilationLibrary = DependencyContext.Default
|
||||
.CompileLibraries
|
||||
.Where(x => !x.Serviceable && x.Type == "project")
|
||||
.ToList();
|
||||
return compilationLibrary.Select(p => Assembly.Load(new AssemblyName(p.Name)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取应用中的所有Type
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Type> GetAllTypes()
|
||||
{
|
||||
var assemblies = GetAssemblies();
|
||||
return assemblies.SelectMany(p => p.GetTypes());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user