Last active
April 21, 2018 13:33
-
-
Save linnet8989/15de881de2191ee961f0de1d6f5fa81f to your computer and use it in GitHub Desktop.
c# get set Property auto Generation and Model class Template (CallerMemberName requires .net 4.5 and higher) for WPF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*-\ | |
s = " \ | |
string Name; \ | |
int Number; \ | |
" | |
s2 = "\ | |
private %s m_%s;\n\ | |
public %s %s\n\ | |
{\n\ | |
get => m_%s;\n\ | |
set => SetProperty(ref m_%s, value);\n\ | |
}\n\ | |
" | |
for s3 in s.split(";"): | |
if s3.strip() and s3.strip()[0] != '/': | |
l = s3.strip().split() | |
s4 = l[-1] | |
if cmp(l[0], "string") == 0: | |
s4 += ' = ""' | |
print s2 % (l[0], s4, l[0], l[-1], l[-1], l[-1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyModel : INotifyPropertyChanged | |
{ | |
//paste your Generated code here | |
public event PropertyChangedEventHandler PropertyChanged; | |
protected bool SetProperty<T>(ref T storage, T value, | |
[CallerMemberName] string propertyName = null) | |
{ | |
if (Equals(storage, value)) { return false; } | |
storage = value; | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment