I'm refactoring a big C# project and it's only natural to find my snowman's unused dead code.
There's this function called FooBar() which looks useful since it has a bunch of code inside it. As is obvious, I was trying to find the references to this function using the "Find All References (F9)" option and it showed up empty-handed (even with the scope to Entire Solution).
Here is the function:
Class A has:
~
public virtual void FooBar(){
<function is empty>
}
~
I have a Class B with:
public override void FooBar(){
~<doing something important here>~
}
I've ran the "Find All References" on both these functions and nothing showed up. I'm assuming its safe to remove but worried if it is, indeed, used somewhere. Apart from this, I've used the "Find in Files" (with Solution-wide scope) for the method name and it showed up empty too.
My question is: Does "Find All References" obtain all the usages? Can it be relied upon to find and remove dead code if nothing shows up in its results?
EDIT:
This function is not part of an API and would not be called by any external code.
To find unused members with a Code Analysis Ruleset, from the Visual Studio menu select File -> New -> File… -> General -> Code Analysis Rule Set. Uncheck all the rules. There are many rules we don't care about right now – and some we probably won't ever care about.
Instead of opening the Nuget Packagemanager and uninstalling things manually there is faster way: right click on the project in the Solution Explorer and go into R# Refactor menu. There you'll find the Remove unused references menu item.
Step 1: From Settings – Type CodeLens and Enable the Editor: Code Lens and JavaScript > References Code Lens to check the references in JavaScript File.
No, there are various reason this will not find code that relies on it.
I'm sure there are more reasons beside these.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With