Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a ReSharper shortcut to find all instantiations of a certain type?

Tags:

c#

resharper

For example:

... new MyClass();


... new MyClass { ... };

If I'm lucky:

... Activator.CreateInstance<MyClass>();

etc.

Any thoughts?

like image 579
joshcomley Avatar asked Oct 29 '25 15:10

joshcomley


2 Answers

Right click the constructor, "Find Usages". I often create a constructor for classes even if I don't need it because of this feature.

Another way, right click on class and click "Find usages". Then click "Filter usages" (in the icon bar), "Show invocation usages". If it's grayed out, there are no invocation usages, which will probably be the case if you use

Activator.CreateInstance<MyClass>();

I found this question because I'm currently looking for a better way of doing this. No luck so far.

like image 80
OleDid Avatar answered Oct 31 '25 05:10

OleDid


Select the constructor and press Shift+Alt+F12. This will show you all explicit calls to the constructor, which should include any factory methods. You can then use the same shortcut to see where they are called from.

like image 20
hammar Avatar answered Oct 31 '25 06:10

hammar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!