Categories
.net DevExpress VS 2005 VS 2008 VS Add In

Autoimplement base class constructors with CodeRush

How often do you derive a class and re-create all of the base constructors? This is not an uncommon task, let’s take a custom exception class for example:

public class MyException: Exception { }

If you right click on Exception and pick Go to Definition from the context menu you’ll see that the Exception class has four constructors:

public class Exception : ISerializable, _Exception { public Exception(); public Exception(string message); protected Exception(SerializationInfo info, StreamingContext context); public Exception(string message, Exception innerException); }

And you better re-create all four in your derived MyException class if you want to follow the design guidelines. This is how MyException should look like (without custom code that is):

public class MyException: Exception { public MyException() { } public MyException(string message) : base(message) { } public MyException(string message, Exception innerException) : base(message, innerException) { } protected MyException(SerializationInfo info, StreamingContext context) : base(info, context) { } }

This is a straightforward derived Exception class definition and needless to say it is quite boring to create all those constructors again and again. That’s why [CodeRush] has a one-click base constructors recreation feature. Position the caret somewhere on the Exception word and invoke [CodeRush] with keyboard shortcut (by default the shortcut is Ctrl+CEDILLA) and instantly all of those boring-to-recreate constructors appear from nowhere. Brilliant.

Categories
DevExpress VS 2005 VS 2008 VS Add In

CodeRush Xpress is free

A stripped (more express) version of CodeRush, called CodeRush Xpress, is available for download at no charge! And even a bunch of refactorings are included. See the announcement or go to the product page directly.

Now you don't have any more excuses to avoid the very handy and useful CodeRush!

UPDATE: I missed the fact that it works only with C#. (thanks to pinkpanter)