by John Papa via JohnPapa.net on 10/3/2010 12:04:00 AM
I’ve talked a lot about Resharper features such as the Find Usages, live templates, and the instant code analysis. But I have not talked about some of the features that are not as prominent but I find especially helpful. So here are a few very simple tips for how to clean your code up using Resharper.
Tip 1) Removing redundant “this” qualifier
Sometimes I add the this statement when I am writing code. It is a habit I got into a long while ago and have had a hard time breaking. I prefer to not have “this.” leading all of my class level properties and methods. Resharper makes this easy to fix. Just remember this sequence:
F12 brings you to the next Resharper warning (or Error). In this case, you will see the “this.” statement (grayed out because it is redundant)
ALT-ENTER displays the Resharper hint window (or you can click the red light bulb)
ENTER removes the redundant qualifier.
This same process works for removing unreachable code.
So this code is the before:
And this code is after:
Sometimes you have methods that accept a type using Generics. And sometimes specifying the type is redundant. Resharper let’s you find these, by, guess what, using:
So this …
becomes this
I like to clean up my Using statements at the top of my class files. It seems some files, like when you create a new Page, have tons of extra “Using” statements. Yes, maybe I’ll need them, but even I do, I’ll let Resharper or Visual Studio’s tools tell me. So let’s get rid of them.
First, I hit the CTRL + HOME keys to go to the top of the page.
Then comes the common sequence:
becomes this:
I love it!
When I create public properties sometimes I forget to make the set accessor private. Do I need to? No, but why expose something that does not need to be exposed. Resharper makes this easy again:
So this
There is so much you can do with Resharper but hopefully this shows you how easy it is to tackle some small refactoring jobs to reduce some code in your project.
Original Post: 5 Easy Tips to Reduce and Refactor Your Code with Resharper
The content of the postings is owned by the respective author. Silverlight Feeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on Silverlight Feeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.