相关疑难解决方法(0)

获取在.NET Core中实现接口的所有类型

使用反射,我如何获得在.NET Core中实现某些特定接口的所有类型?我注意到.NET 4.6中可用的方法不再可用.

例如,此代码不起作用.

var type = typeof(IMyInterface);
var types = AppDomain.CurrentDomain.GetAssemblies()
    .SelectMany(s => s.GetTypes())
    .Where(p => type.IsAssignableFrom(p));
Run Code Online (Sandbox Code Playgroud)

它抛出The name 'AppDomain' does not exist in the current context错误.

.net c# reflection lambda .net-core

13
推荐指数
3
解决办法
1万
查看次数

标签 统计

.net ×1

.net-core ×1

c# ×1

lambda ×1

reflection ×1