Wednesday, June 18, 2014

fast replace by visual studio regular expression

Purpose :
Replacing code.
from simple data holder to wrapper of dictionary.
simple data holder:


After some code refactoring, all data stored in Dictionary, and data holder look like this:

private class DataHolder
{
public int SomeData { get; set; }
public string NameOfData { get; set; }
}
view raw gistfile1.cs hosted with ❤ by GitHub

private class DataHolder
{
public int SomeData { get { return dict.GetValue("SomeData"); } set { dict.SetValue("SomeData", value); } }
public string NameOfData { get { return dict.GetValue("NameOfData"); } set { dict.SetValue("NameOfData ", value); } }
}
view raw gistfile1.cs hosted with ❤ by GitHub

To replace all values (30) data values, i use visual studio find and replace capability to use regular expression.

 This is value of find:
 (\w*) (\w*)\s{ (get;) (set;) }
This is value of replace.
 $1 $2 { get { return dict.GetValue<$1>("$2");} set { dict.SetValue("$2",value); } }

No comments:

Post a Comment