Archive

Posts Tagged ‘Variables’

Code Issues specific for declaring variables and constants

August 9th, 2012 Comments off

In addition to code issues specific for declaring types, CSharp and Visual Basic language specifications have a few restrictions on declaring constant or simple variable declarations. Having this issue in the code editor right in front of a developer allows him to fix the issue immediately without compiling the project.

Read more…

Promoting locals and constant value expressions into parameters

July 31st, 2012 Comments off

There are times when you realize that a local variable or a field reference within a method would be more useful if it was a parameter. Having a new parameter on a method will increase its flexibility for consumers. To convert the local variable, you should remove its declaration from the body of the method, add it as a parameter and replace all occurrences of a local to a new parameter. The same steps must be performed in the case of field references. Furthermore, all method references in the entire solution should be updated to pass a new value as an argument to a method with a new signature.

Read more…

Refactorings for changing members accessibility and scope visibility

February 13th, 2012 Comments off

There are a couple of visibility-changing refactorings shipped in DevExpress Refactor! Pro.

Reduce Visibility

This refactoring allows you to quickly reduce the visibility of a member to match the highest calling visibility, in other words, to restrict the visibility as much as possible.

Read more…

Refactorings for variable scope widening (Widen Scope)

January 24th, 2012 Comments off

The scope of a variable declaration determines its visibility to the rest of a program. Scopes can be member-level, class-level and nested, where an inner scope may re-declare the meaning of a variable from an outer scope.

When declared inside a member, the scope of the variable is the entire member after the variable declaration, including all nested code blocks. This means that the variable is available to use within the member but when control passes to another member, the variable is unavailable.

Read more…

Declaring fields using CodeRush consume-first declaration features

December 16th, 2011 Comments off

Unlike the local variable declarations, fields are simply variables that are declared directly within the code block of a class or a structure. Fields are declared in the type block by specifying the access level of the field, the type of the field and the name of the field. A field may also include a readonly modifier. This type of field can only have its value set directly in its declaration or from within a constructor of its containing class.

Read more…

Declaring locals using CodeRush consume-first declaration features

December 16th, 2011 Comments off

Local variable declarations are the most often used types of declarations in code. A local variable is a type of variable declared by local variable declaration inside a block the variable is intended to be local to. The local variable declaration explicitly defines the type of the variable that has been declared along with the identifier that names the variable. You can also declare implicitly typed local variables, whose type is inferred by the compiler from the expression.

Read more…

Refactorings for implicitly-typed local variables

September 27th, 2011 4 comments

Implicitly-typed local variables are variables declared without specifying the type explicitly. The type of such variables is being inferred from the expression that is used to initialize the variable at the time the code is compiled. Implicitly-typed variables are really useful for LINQ that creates anonymous types in queries, and for which you want to assign variables. However, implicitly-typed locals can be used with any variable declaration to enhance the readability, for example:

Refactor! Implicit variable sample

Read more…

Code Issues – Undisposed local

July 13th, 2011 Comments off

The Undisposed local code issue of the warning type highlights local variables that implement the System.IDisposable interface and are not explicitly disposed. The IDisposable interface was designed to provide a standard way to release unmanaged resources by calling its Dispose method. If the object is IDisposable, it is a good idea to dispose of it when you no longer need it, especially if the object uses unmanaged resources. These are resources that the .NET garbage collector does not manage on our behalf and is unable to clean-up automatically. They include items such as streams, files, database connections, handles and other operating system objects. If the memory and system resources that they use are not properly released, a program may suffer from memory leaks or problems due to locked resources.

Read more…