Archive

Posts Tagged ‘Constructors’

Declaring methods and constructors using CodeRush

September 21st, 2012 Comments off

When writing a new code, it usually implies writing a not-declared code like a method invocation, property calls, etc. To help you quickly create the required declarations, there are a lot of code generation providers for declaring methods, properties, fields, locals and everything else. Let’s review the method and constructor code declaration providers:

  • Declare Constructor
  • Declare Method
  • Declare Method (abstract)

Read more…

How to create a method or constructor overload using CodeRush

July 31st, 2012 Comments off

The process of creating more than one method in a class with the same name is called as method overloading. Method overloading allows the developer to define several methods with the same name but with a different set of parameters. This way, one does not have to remember the names of multiple functions that serve a similar core purpose. When a call is made to one of these overloaded methods, the compiler automatically determines which of the methods should be used according to the arguments used in the call.

Read more…

CodeRush code issues specific to constructors

September 29th, 2011 Comments off

A constructor is a special class member that is executed when a new object is created. There are two types of constructors: instance constructors and static constructors. Instance constructors are used to create and initialize instances of classes or structures. A static constructor is used to initialize a class itself. A static constructor is called automatically to initialize the class before the first instance is created or any static members are invoked.

Read more…

Code Issues – Base type constructors are not implemented

April 26th, 2011 Comments off

The Base type constructors are not implemented code issue is an alternative code issue to the “Can implement base type constructors“. The different between these two is in their type – one is an error and another one is a hint. When the current type doesn’t implement non-default constructors from a base type the “Base type constructors are not implemented” error is shown.

Read more…

Code Generation – Add Missing Constructors code provider

April 26th, 2011 Comments off

The Add Missing Constructors code provider from CodeRush allows you to add constructors from the ancestor class to the current class or structure, which are not implemented.

Imagine you are creating a descendant of the System.Exception class:

CodeRush - New Exception descendant (CS)

Read more…

Code Issues – Can implement base type constructors

April 26th, 2011 Comments off

Cause:

The Can Implement base type constructor code issue of type hint suggests that you implement the constructors that are missing for the current class, but exist in the ancestor (base) class.

For instance, once you implement your custom exception class derived from the System.Exception, you have to provide the full set of its constructors. Failure to provide all of the constructors of the Exception class can make it difficult to correctly handle exceptions. For example, the constructor with the signature “Exception(string, Exception)” is used to create exceptions that are caused by other exceptions. Without this constructor, you cannot create and throw an instance of your exception descendant that contains an inner exception, which is what managed code should do in such situations.

Read more…

Smart Constructor – Generating advanced type constructors in three keystrokes

April 19th, 2011 Comments off

The Smart Constructor CodeRush feature allows you to add constructors to the current class or structure, and pass type members, like fields and properties for initialization through its parameters. Creating a constructor is as simple as just typing three keys: “cc & Space”:

CodeRush Smart Constructor preview

Read more…