Imagine a class with lot of fields.
Now, you would want to build a constructor that initializes all or many of the fields by assigning arguments to coresponding fields so you don’t need to initialize all fields one by one, plus you have the guarantee that all fields are initialized. Makes sense, right. Now, how would you write such a constructor? You might just use all of your 20 fingers and type it. Pretty annoying, isn’t it. Afterall all the information is already there.
So, meet one of the CodeRush‘s feature I love: Smart Constructor. Just move the caret to the point where you want your constuctor created and type cc [SPACE] (assuming default CodeRush settings). A window like this will appear:
You can uncheck fields at will. After you are done just press [ENTER].
/// <summary>
/// Creates a new instance of Person
/// </summary>
/// <param name=”name”></param>
/// <param name=”surname”></param>
/// <param name=”age”></param>
/// <param name=”address”></param>
/// <param name=”city”></param>
/// <param name=”zip”></param>
/// <param name=”height”></param>
public Person(string name, string surname, int age, string address, string city, string zip, float height)
{
this.name = name;
this.surname = surname;
this.age = age;
this.address = address;
this.city = city;
this.zip = zip;
this.height = height;
}
}
Isn’t this feature just lovely? CodeRush just sucks the metadata from the declaration and creates a constructor with all arguments you’ve selected. It certainly saves a lot of annoying typing for me and prevents me to type wrong assignments. And this is just one of the million CodeRush’s features.