Archive

Posts Tagged ‘Conversion’

Code Providers – Convert to Integer

August 30th, 2012 Comments off

The Convert to Integer code provider allows you to wrap an expression returning a non-integer value to Math.Ceiling, Math.Floor, or Math.Round. Consider the following code sample:

CodeRush Convert to Integer sample code

Read more…

Refactorings for Loops and Blocks overview

August 28th, 2012 Comments off

This is just a quick overview list to organize a bunch of refactorings that deal with loops and blocks. Click the refactoring name to learn more about it.

Add Block Delimiters

This refactoring embeds a single statement into curly braces.

Consolidate Using Statements

This refactoring combines several neighboring or nested using statements that cover variables of the same type into a single using statement.

Read more…

The Lock to Try/Finally refactoring

August 27th, 2012 Comments off

Locking is essential in programs with multi-threading. It restricts code from being executed by more than one thread at the same time. The lock statement gets the exclusive monitor for an object and ensures that no other thread can access the object until the lock is released.

The lock statement automatically generates exception safe code, and in fact it is a syntactic shortcut for a call to the methods Monitor.Enter(obj) and Monitor.Exit(obj) with a try/finally block. However, if the thread is aborted after the lock is acquired but before entering the try block, the lock will not be released. Also, bear in mind that the Monitor.Enter() waits to acquire the lock forever which may introduce a possible deadlock condition.

Read more…

Refactoring using statements with CodeRush/Refactor!

May 9th, 2012 Comments off

As many of you know, the using statement is a good tool for managing types which will be accessing unmanaged resources. The using statement provides a simple and convenient syntax that ensures that objects that implement the IDisposable interface are correctly disposed.

If the object is not disposed, CodeRush highlights the undisposed variables with the “Undisposed local” code issue:

Read more…

Refactorings specific to auto-implemented properties

July 12th, 2011 Comments off

Auto-implemented properties enable you to quickly specify a property without having to write logic for the property accessors. The auto-property’s logic and the field serving as a backing store are automatically generated by the compiler. Such properties appeared in C# version 3.0 and Visual Basic version 10.0.

Read more…