Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C sharp code cleanup : resharper

Tags:

c#

resharper

I just used Resharper and it made me feel as if i don't know how to code at all in C#; it gave me a lot of suggestions; few of them are:

1) SomeObject o = new SomeObject();

Resharper will convert to :

var o = new SomeObject()

2) this.Loaded += new RoutedEventHandler(MainPage_Loaded);

to

this.Loaded += MainPage_Loaded;

3) convert my variables and putting _ in front of all instance variables.

4) Removing class parent's name. I tested this on Silverlight.

public partial class MainPage : UserControl

to

public partial class MainPage

5) replace instance variable

 this.variable = somevalue

to

 variable = somevalue

Are all of these really necessary? Is it really going to affect the efficiency of my program? I mean what good is it going to do by replacing my class names with var keyword. After all var is also replaced with class name at compile time. Is it doing because it has been programmed to do or do these things really affect in some or another way?

like image 429
TCM Avatar asked Dec 30 '10 16:12

TCM


1 Answers

This behaviour is all configurable in ReSharper settings. There are a mix of code clean-up rules (e.g. whether to replace usages with var - I don't!), code style rules (e.g. variable naming) and formatting rules (e.g. how to place braces).

I wrote an article that gives an overview of these settings and how they can be used to shape coding standards and then be automatically applied via code cleanup:

http://gojisoft.com/blog/2010/05/10/coding-standards-using-resharper/

At the end of the day a lot of them are concerned with coding style and removing redundant code, they have no affect on the compiled code. You can configure many of them to suit you or your team's coding style.

like image 67
Tim Lloyd Avatar answered Oct 12 '22 21:10

Tim Lloyd