I'm working on a new project where I laid out the class structure in ArgoUML and generated the C# code. This was my first time using ArgoUML and I found that I didn't like the generated code that much, and had a lot of changes to make. One such change was to refactor my public members into private members exposed by public properties. In Visual Studio 2005 this is no problem with the built in refactoring. This project, however, needs to use the 1.1 .NET framework, so I'm stuck using Visual Studio 2003. So I resorted to Find & Replace using Regular Expressions.
The regular expression used for the Find:
^{:b*}public {:a+} {:a+};
And the expression used for the Replace:
\1public \2 \3\n\1{\n\1\tget { return m_\3; }\n\1\tset { m_\3 = value; }\n\1}\n\1private \2 m_\3;
This results in code like this
public string Name;
being replaced with this
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
private string m_Name;
I suppose it would be a little better to somehow replace the capital first letter in the private member with a lower case equivalent, but it's not really that big of a deal ... at least, not big enough to spend more time on this task.
Edit: I need to come up with a better format for posting code.
Labels: programming, regex