Find dead .NET code
One benefit of using ReSharper is that it shows you bits of your own code that you’re not using. ReSharper is actually very smart about it: not only will it point out code that isn’t used anywhere, but it will detect more complicated cases – for example the case where a field is both declared and initialized, but nothing apart from initialization actually happens to it.
Let’s take a look at an example. Say we have a class Person
defined as follows:
Now, ReSharper will indicate that the _name
field isn’t used. If you hover the mouse pointer over this field, you’ll get the following message:
If you now press Alt+Enter over the _name
field, ReSharper will offer an option to remove the name field and any assignment to it:
And here is the result:
Notice that now ReSharper informs us that the parameter can also be removed. We use the corresponding quick-fix:
And we get an empty constructor which, as you may have guessed, is also not needed, since a default constructor is implemented by default. Once again, ReSharper picks up on it and offers us an option to get rid of the constructor: