Is there a (better) way to find all references to

2020-03-01 02:58发布

问题:

Visual Studio's "Find All References" function works nicely for finding references to a property, and as it happens the "Call Hierarchy" does this too - it's even better in fact, as it sorts them by calling method.

My problem however is that neither of these methods discriminate between the setter and getter, and so I'm reduced to using find-in-files for "PropertyName =".

That seems like a step backwards (and would obviously not find code using "PropertyName += value" or similar), so I was wondering if I'd missed a simple way of persuading the "Call Hierarchy" function of Visual Studio to work on a property setter or getter specifically?

回答1:

It is possible in Visual Studio 2019 to sort and filter by "Kind" using the "Find All References" function. The feature was requested on Microsoft's developercommunity forum

The "references" window with the "Kind" column is displayed to the very right, highlighted by a orange box.



回答2:

Resharper can do that for you.

Without R#, one way would be to temporarly set the setter to private and recompile. That will give an error everywhere you're trying to set. Not pretty, but faster than any other method I can think of.