blogs.conchango.com

welcome to the conchango blogging site
Welcome to blogs.conchango.com Sign in | Join | Help
in Search

Merrick Chaffer's Blog

Regular Expression to turn public fields into public properties

In Visual Studio, you can use the find and replace utitlity in regular expression mode, with the expressions below to turn code such as this...

        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 0)]
        
public string executeSoapV1Result;

into

        private string _executeSoapV1Result;

        [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue = false, Order = 0)]

        public string executeSoapV1Result

        {

            get

            {

                return _executeSoapV1Result;

            }

            set

            {

                _executeSoapV1Result = value;

            }

        }

Find What:
{\[System\.Runtime\.Serialization\.DataMemberAttribute(.*)\]}\n{(.*)}public {(.*)} {(.*)};$


Replace with:

private \3 _\4;\n\1\npublic \3 \4\{\nget\{ return _\4;\n\}\nset\{ _\4 = value;\n\}\n\}


With Use:

Regular expressions option.


Then do a Ctrl+K, Ctrl+D shortcut to reformat the output correctly.

Published 30 March 2007 15:41 by merrick.chaffer

Comments

No Comments
Anonymous comments are disabled
Powered by Community Server (Personal Edition), by Telligent Systems