我有一个项目中多次提到。 我需要找到所有实现IMyInterface的接口类型。
I have a project contains many references. I need to find all the types that implement IMyInterface interface.
我试过 AppDomain.CurrentDomain.GetAssemblies()的SelectMany(X => x.GetTypes())。,但它并没有在参考文献中返回的所有类型。
I tried AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()) but it didn't returned all the types in the references.
我该怎么办呢?
推荐答案我想这个问题可能是你的一些引用的程序目前尚未加载。你可以得到所有引用的程序与 GetReferencedAssemblies - 但这只会产生名字
I guess the problem might be that some of your referenced assemblies are not currently loaded. You can get all referenced assemblies with GetReferencedAssemblies - but this will only yield the names.
如果你愿意,你可以去和加载组件与的Assembly.Load ,并进一步对其进行检查。
If you want you can go on and load the assemblies with Assembly.Load and inspect them further.
因此,一个可能的片段应该是
So a possible snippet should be
var types = System.Reflection.Assembly.GetExecutingAssembly() .GetReferencedAssemblies() .SelectMany(name => Assembly.Load(name).GetTypes()) .Union(AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()));
寻找实现你的接口类型:
to search for the types implementing your interface:
var withInterfaces = types.Where(t => t.GetInterfaces().Any(i => i == typeof(IDisposable)));如果这不招我丢失了...
If this does not the trick I'm lost as well...
更多推荐
如何获得的所有类型在参考文献中实现IMyInterface的
发布评论