简体   繁体   中英

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?

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.

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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM