Viv*_*ndi 3 c# reflection .net-core asp.net-core
我正在尝试获取实现某个抽象类的所有类.我正在尝试使用以下代码执行此操作:
var type = typeof(BaseViewComponent);
var types = Assembly
.GetEntryAssembly()
.GetReferencedAssemblies()
.Select(Assembly.Load)
.SelectMany(s => s.GetTypes())
.Where(p => type.IsAssignableFrom(p));
Run Code Online (Sandbox Code Playgroud)
但到目前为止,我只能自己获得抽象类.不是任何实现该基类的类.
我需要更改什么才能获得实现此抽象基类的所有类?
using System.Reflection;
using Microsoft.Extensions.DependencyModel;
Run Code Online (Sandbox Code Playgroud)
var asmNames = DependencyContext.Default.GetDefaultAssemblyNames();
var type = typeof(BaseViewComponent);
var allTypes = asmNames.Select(Assembly.Load)
.SelectMany(t => t.GetTypes())
.Where(p => p.GetTypeInfo().IsSubclassOf(type));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
956 次 |
最近记录: |