Friday, December 17, 2010

Invert assignment direction in Visual Studio

Ever wanted to switch the property assignments in a class, for instance in a Set_ of Get_ method.

   1: private Internal _i = new Internal()
   2:  
   3: void SetObject(Object o)
   4: {
   5:     _i.Name = o.Name;
   6: }
   7:  
   8: Object GetObject()
   9: {
  10:     Object o = new Object()
  11:     o.Name = _i.Name;
  12:     return o;
  13: }

Now, above example has only on assignment, but what if you have like 10. There is a way to do this using the build-in replace functionality.

Select the lines you want to swap, Ctrl+H, then replace:

Replace

   1: {.*}:b*=:b*{.*};

with

   1: \2 = \1;

with [Look in:] set to [Selection].

Check the [Use:] checkbox, and select [Regular expressions]

Happy Coding.

0 comments: