How to transform old properties to automatic properties with a ‘simple’ search and replace

Say you have a (typically autogenerated) class with properties like:

public partial class Project : IExtensibleDataObject
{
    public System.Runtime.Serialization.ExtensionDataObject ExtensionData
    {
        get
        {
            return this.extensionDataField;
        }
        set
        {
            this.extensionDataField = value;
        }
    }

Now you can fire up the Find & Replace dialog in VS and enter the following "simple" expression in Find What:

\n:b*\{[:b\n]*get[:b\n]*\{[.:b\n]*.*[.:b\n]*\}[.:b\n]*set[:b\n]*\{[.:b\n]*.*[.:b\n]*\}[.:b\n]*\}

And use the following expression for the replace:

 { get; set; } 

image

Don't forget to set the Use: Regular expressions option....

Read full article

No Comments