How to find what class(es) implements an interface

2020-02-14 20:32发布

The closest I could find to this question was this one: Getting all types that implement an interface

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.

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?

Thanks, Jeff

2条回答
Melony?
2楼-- · 2020-02-14 20:50

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.

查看更多
家丑人穷心不美
3楼-- · 2020-02-14 21:01

Using ReSharper, right-click on the Interface, go to Implementation, choose the one you want to see from the list it populates.

I don't think there's a way to do it programatically, but if you just mean in the IDE, this is the easiest way to do so.

查看更多
登录 后发表回答