如何查找类(ES)实现一个接口(.NET)接口、ES、NET

2023-09-02 02:05:16 作者:巫祈

我能找到这个问题最近是这一个:http://stackoverflow.com/questions/26733/getting-all-types-that-implement-an-interface-with-c-3-5

The closest I could find to this question was this one: http://stackoverflow.com/questions/26733/getting-all-types-that-implement-an-interface-with-c-3-5

但是,这是在code使用,并使用它,我不得不改变code,重新编译和运行。我在想,如果有对我来说,只是查找实现某个接口的所有类简单的方法。

But that is for use in code, and to use it I'd have to change the code, recompile and run. I was wondering if there is a simpler way for me to just lookup all classes that implement a certain interface.

我似乎要面临的问题相当频繁,以至于我正在寻求一些更容易/更通用的方法来找到我的答案。最近,我想找出哪些类我可以用它实现的ISet,这并不重要,对我来说哪个类,只需要一个用于创建一个实例。

I seem to be faced with the question fairly often enough that I am seeking some easier/more generic way to find my answer. Most recently I wanted to find out what classes I could use that implement ISet, it didn't matter to me which class, just needed one to use to create an instance.

所以,我想知道是否有什么办法,只是找到实现指定接口的所有类?

So I was wondering if there was any way to just find all classes that implement a given interface?

谢谢, 杰夫

推荐答案

没有有没有更简单的方法。我想这样是pretty的容易做的。这只是三线。 (您想测试它的接口的集合的情况下),如果你需要做很多次在一排,你可以缓存结果以列表或字典。

No there's not an easier way. I guess that way is pretty easy to do. It's just three lines. You can cache the results in a list or dictionary (in case you want to test it for a collection of interfaces) if you need to do it many times in a row.

如果你只需要一个工具,反射做的。

In case you need just as a tool, Reflector does it.