Reputation: 2484
I want to find all calls to DateTime.ToString
references in my assembly. In Visual Studio you can "Find All References" by right clicking on ToString
; however, that returns all references to ToString
for all classes and not just DateTime
.
A regular search for DateTime.ToString
won't work because of the following example:
DateTime myDate = new DateTime();
myDate.ToString();
Any suggestions?
Upvotes: 21
Views: 2687
Reputation: 2085
In Visual Studio 2019, right-click on the desired method name, and then click "View Call Hierarchy." A "Call Hierarchy" window appears at the bottom (by default) of Visual Studio. In the left pane, you'll see a tree representation of the projects that call the method. Within each project, the first item is "Calls To [MethodName]." Expand this first item for a list of methods. Clicking each method will change the right pane of the "Call Hierarchy" window to show the lines where the method is called. Double-click these lines to go to them and address them individually.
Upvotes: 3
Reputation: 667
In VS2015 when you try to Find References for override method, you have them grouped by type in
Results like this:
Find Symbol Results
Upvotes: 9
Reputation: 73442
In visual studio, AFAIK it is not possible, though resharper can.
In resharper, Find Advanced Usages window you can filter out which type you're looking for. You can specify less derived or more derived.
So in this case, you can filter out only DateTime
, or all ValueType
or System.Object
.
In this case I guess visual studio can't help, still I'd like to share some tricks.
For example: If you want to find all references of PropertyChanged
event of your Person
class assuming person implements INotifyPropertyChanged
, You are going to get tons of references as there are numerous classes which implements INotifyPropertyChanged
.
What you can do about it is, just go to Person
class and comment out the implementation of INotifyPropertyChanged
interface. Then Find all references in visual studio will tell you only the references of Person
class. Not all types.
At least I hope this trick can help in some other place if not now.
Upvotes: 1
Reputation: 4567
You should use ReSharper for that.
Steps:
myDate.ToString();
ToString
tokenFind Usages Advanced ...
menu itemFind
Upvotes: 17