.NET Core 1.0, Enumerate All classes that implement base class

假如想象 提交于 2019-12-05 07:53:48

.Net Core currently (1.0 RTM) does not support AppDomain.GetAssemblies() or a similar API. It's likely that it will support it in 1.1.

Until then, if you need this feature, you will need to stick with net452 (i.e. .Net Framework) instead of netcoreapp1.0.

Will this work?

var all =
        Assembly
        .GetEntryAssembly()
        .GetReferencedAssemblies()
        .Select(Assembly.Load)
        .SelectMany(x => x.DefinedTypes)
        .Where(type => typeof(ICloudProvider).IsAssignableFrom(type.AsType()));
foreach (var ti in all)
{
    var t = ti.AsType();
    if (!t.Equals(typeof(ICloudProvider)))
    {
        // do work
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!