Home > Refactorings > Refactorings – Convert to Point

Refactorings – Convert to Point

June 28th, 2011

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.

Depending on the project type and numeric parameter types, the Convert to Point may use one of the following Point structures:

  • System.Drawing.Point
  • System.Drawing.PointF
  • System.Windows.Point (in WPF)

Note however, if the project doesn’t reference the assemblies for the Point structure (e.g. System.Drawing.dll) the refactoring won’t be available.

The Convert to Point can be useful when you work with graphics and appropriate graphic objects, for example:

void DrawLine(int startX, int startY, int endX, int endY)
  _Graphics.DrawLine(Pens.White, startX, startY, endX, endY);

In the code preview hint you are able to see the resulting code:

DevExpress Convert to Point refactoring preview

Applying it twice will result in:

void DrawLine(Point start, Point end)
  _Graphics.DrawLine(Pens.White, start.X, start.Y, end.X, end.Y);

All calling sites will be updated automatically once the refactoring is performed.

Products: Refactor! Pro
Versions: 11.1 and up
VS IDEs: any
Updated: Jun/28/2011
ID: R030

Similar Posts: