Skip to content

Instantly share code, notes, and snippets.

@fliedonion
Created October 4, 2018 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fliedonion/540e8f8a7a83983d0952b68253ff552e to your computer and use it in GitHub Desktop.
Save fliedonion/540e8f8a7a83983d0952b68253ff552e to your computer and use it in GitHub Desktop.
Regex for Convert C# Field to Property with INotifyPropertyChanged

Find pattern is like this:
public (.+) (?!PropertyChanged)(.+);

Replace is:

public $1 $2 {
    get { return \l$2; }
    set {
        if(\l$2 != value) {
            \l$2 = value;
            OnPropertyChanged("$2");
        }
    }
}
private $1 \l$2;

Replace (single line textbox ver):
public $1 $2 {\r\n get { return \l$2; }\r\n set { if(\l$2 != value) { \l$2 = value; OnPropertyChanged("$2"); } }\r\n}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment