Archive

Posts Tagged ‘Parameters’

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…

Refactorings – Decompose Parameter

September 9th, 2011 Comments off

The Decompose Parameter refactoring splits a single parameter into one or more parameters, depending on the function of the original parameter. The refactoring analyzes how the parameter is used and which of its properties are accessed, after which it can replace a single parameter into several others of the appropriate type for each property being accessed through the original parameter.

Read more…

Refactorings – Convert to Point

June 28th, 2011 Comments off

The Convert to Point refactoring is based on the Introduce Parameter Object refactoring with the difference that it doesn’t create a new object for parameters. Instead, it uses a ‘Point’ structure when there is a pair of two numeric parameters of a method definition are selected.

Read more…

Refactorings – Use Named Arguments

June 28th, 2011 Comments off

Named Arguments is a feature of the C# and Visual Basic languages introduced in the .NET Framework version 4.0. Named arguments allow you to explicitly specify a name for an argument for a particular parameter by associating the argument with the parameter’s name, rather than with the parameter’s position in the parameter list. Using named arguments frees you from the need to remember or to look up the order of parameters in the parameter lists of called methods.

Read more…

Code Issues – Unused type parameter

February 14th, 2011 Comments off

Cause:

This code issue of a dead code type shows type parameters to a generic type, or method definitions that are not referenced within its scope, and can be removed. In a generic type or method definition, a type parameter is a placeholder for a specific type that a client specifies when they instantiate a variable of the generic type. Removing the unused type parameter may improve readability.

Read more…

Refactorings – Introduce Parameter Object

August 13th, 2010 Comments off

The Introduce Parameter Object refactoring consolidates selected parameters into single object. If you frequently need to pass similar sets of values to methods that tend to be passed together, it might be useful to encapsulate these values into an object that carries all of this data. It is worthwhile to turn these parameters into objects just to group the data together. As the result, calling statements will become more compact and you will be able to add data processing logic to the newly declared object. This refactoring is also useful because it reduces the size of the parameter lists, and long parameter lists are hard to read and understand.

Read more…

Refactorings – Remove Parameter

August 13th, 2010 Comments off

Also known as Remove Unused Parameter. This refactoring removes an unused parameter from a method declaration, and updates all calls accordingly. It is very useful when a parameter is no longer used by the method body. A spurious parameter doesn’t cause any problems, and you probably might need it again later. But most of the time this is the wrong choice, because a parameter indicates information that is needed. In this case, a caller has to worry about what values to pass for a fictitious, unused parameter. By not removing the parameter you are making further work for everyone who uses the method.

Read more…

Refactorings – Add Parameter

August 13th, 2010 Comments off

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. Bear in mind that if there are alternatives available against doing this refactoring, it is preferred to use those alternatives instead, because they don’t lead to increasing the length of parameters lists. Long parameter lists are hard to remember and often involve data clumps.

Read more…