Archive

Posts Tagged ‘Methods’

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…

Refactorings for changing member signatures overview

August 9th, 2012 Comments off

This is just a quick list to organize a bunch of refactorings that change member signatures. Click the refactoring name to learn more about it.

Add Parameter

The refactoring adds a new parameter to a method declaration and updates all calls accordingly. This refactoring is useful when you need to quickly add a new parameter to an existing method because it needs more information from its caller that wasn’t passed in before.

Read more…

Reordering method parameters with Visual Studio and CodeRush

July 31st, 2012 Comments off

Sometimes you may find that various method parameters are ordered illogically, or when method parameters appear in a different order relative to one another, similar methods. In this case, if you prefer the parameters appear in a consistent and logical order, you must not only change the order in the method signature but also update all calls to the method. Take into account complex cases when you can move return values of a function into our parameters and vice versa. Refactoring such complex cases is a rather complex and time-consuming task, especially if there are too many calls.

Read more…

How to safely rename a public API member and mark it obsolete

July 31st, 2012 Comments off

There are times when public API members must be deprecated or its signature must be changed. In this case, we can not remove or modify public members, because other application that depend on these APIs may become broken and/or uncompilable. If you’d like to supersede a public member, you can use a special attribute called ‘Obsolete’. The Obsolete attribute marks an API member as one that is no longer recommended for use.

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…

Converting methods into extension methods based on its parameters

July 23rd, 2012 Comments off

The Make Extension refactoring converts the chosen public method into an extension method based on the selected parameter type. To apply the refactoring, select the parameter for which you want to create an extension method:

Read more…

Converting methods to functions or procedures

October 31st, 2011 Comments off

The simplest type of method is one that performs a task without requiring any parameters and without returning any information – let’s call them procedures (or void methods). Methods that use some type as the return value – are functions.

Sometimes, when we declare a method with a return value, we may realize that we don’t actually need this return value, and instead, need a simple void method that does not return anything. On the other hand, we marked a method as void, but may require it to be a function, returning a value.

Read more…

Code Issues for anonymous methods and lambda expressions

October 31st, 2011 Comments off

We already reviewed the refactorings for anonymous methods and lambda expressions and know how to deal with these language structures. Now its time to review what Code Issues for anonymous methods and lambda expressions CodeRush Pro provides.

Read more…