joshcomley
joshcomley

Reputation: 28818

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

For example:

... new MyClass();


... new MyClass { ... };

If I'm lucky:

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

etc.

Any thoughts?

Upvotes: 4

Views: 1106

Answers (5)

OleDid
OleDid

Reputation: 141

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.

Upvotes: 4

hammar
hammar

Reputation: 139840

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.

Upvotes: 2

Thorsten Hans
Thorsten Hans

Reputation: 2683

The Find Usages Feature is able to find all occurrences of any symbol. ReSharper is able to find all explicit references and the references created by using Reflection. See http://www.jetbrains.com/resharper/features/navigation_search.html#Find_Usages

Upvotes: 0

John Saunders
John Saunders

Reputation: 161773

Your first two are both calls to the same constructor. Simply doing a Find Usages will locate them (ALT+F7).

Upvotes: 0

Dan Abramov
Dan Abramov

Reputation: 268235

Find Usages menu available on any member and type shows all usages, including instantiation.
I'm not aware of any way to filter the results to instantiation only.

Upvotes: 0

Related Questions