Building class constructors with ease using CodeRush

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].



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.

Leave a Reply