Skip to content

Instantly share code, notes, and snippets.

@PaulDMendoza
Last active January 29, 2017 23:04
Show Gist options
  • Save PaulDMendoza/1ec5e02c5c3527d1ab7134d202c686c6 to your computer and use it in GitHub Desktop.
Save PaulDMendoza/1ec5e02c5c3527d1ab7134d202c686c6 to your computer and use it in GitHub Desktop.
Visual Studio Find and Replace to convert auto property to set an "_isDirty" flag
Guid _UserID = Guid.Empty;
public Guid UserID { get { return _UserID;} set { _isDirty = true; _UserID = value; } }
string _EmailAddress = null;
public string EmailAddress { get { return _EmailAddress;} set { _isDirty = true; _EmailAddress = value; } }
string _Name = null;
public string Name { get { return _Name;} set { _isDirty = true; _Name = value; } }
int _TimesFound = 0;
public int TimesFound { get { return _TimesFound;} set { _isDirty = true; _TimesFound = value; } }
public Guid UserID { get; set; }
public string EmailAddress { get; set; }
public string Name { get; set; }
public int TimesFound { get; set; }
To use this add a property to you class like "public bool _isDirty { get; set; }". Then in Visual Studio just use the find and replace tool and enable Regex.
public ([\w?\]\[]+) ([a-zA-Z_]+) { get; set; }
$1 _$2 = null; \r\n\t\tpublic $1 $2 { get { return _$2;} set { _isDirty = true; _$2 = value; } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment