0

In a C# program, how can I find all the classes which implement a given set of interfaces?

Can an IDE such as Visual Studio 2015 help?

Can text processing tools such as grep, awk help?

Can editor such as emacs help?

Sergey Kalinichenko
  • 675,664
  • 71
  • 998
  • 1,399
Tim
  • 1
  • 122
  • 314
  • 481
  • Take a look at this one: http://stackoverflow.com/questions/620376/how-do-you-find-all-implementations-of-an-interface – Akshay Mahajan Apr 11 '17 at 19:49
  • Thanks. Does the linked question address my question for implementing multiple interfaces? – Tim Apr 11 '17 at 19:50
  • That's definitely not a duplicate. However, it's easy to confuse for a duplicate, so I edited the title to make it clear that finding implementations of a single interface is not enough. – Sergey Kalinichenko Apr 11 '17 at 19:59
  • If you have a running program with all assemblies loaded in app domain, you can enumerate through all classes, and print the names of classes that implement the interfaces that you want to find. I don't think ReSharper or any other tool can find simultaneous instantiations, though. `grep`, on the other hand, is not going to work because of a possibility to implement interfaces indirectly by inheriting from some class that implements the interface. – Sergey Kalinichenko Apr 11 '17 at 20:06
  • Do you need to find all those classes at runtime? Or when you are editing the source code? – vyrp Apr 11 '17 at 20:13
  • When i am trying to understand the source code, whether it is reading or debugging. @vyrp http://stackoverflow.com/a/43354838/156458 – Tim Apr 11 '17 at 20:16
  • 1
    I have never done it, but maybe create a Visual Studio extension and use the Roslyn API – vyrp Apr 11 '17 at 20:19
  • how is an extension created usually? @vyrp – Tim Apr 11 '17 at 20:26
  • https://www.infoq.com/news/2011/10/Rosyln-Extensions or https://msdn.microsoft.com/en-us/magazine/dn879356.aspx. But like I said, I've never done it. Maybe someone who has can guide you better. Also, this is an overkill if you only want to find those classes once. An extension would be useful if you want to do that repeatedly for several projects. – vyrp Apr 11 '17 at 20:36
  • Maybe it would be overkill, but he could offer it for other people (like me) as well and would do a great thing for the public ;) – MetaColon Apr 11 '17 at 23:33

0 Answers0