Matt Casto's .NET Journal RSS 2.0
 Friday, October 20, 2006
My first goal on 43 Things was to create a blog, so here we are. I'm planning on using this blog to post topics about software development, but I may sneak in something personal every now and then. Now it's time to change that goal to something like "don't let your blog stagnate."

Labels:

Friday, October 20, 2006 11:55:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
blog
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: ,

Friday, October 20, 2006 9:12:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
programming | regex
Central Ohio Day of .NET

About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Matt Casto
Sign In
All Content © 2008, Matt Casto
Theme based on DasBlog theme 'Business' created by Christoph De Baene (delarou)