I suggest a feature that help us to create similar propeties.
This feature improve language productivity and maintainability.
We frequently create properies something similar like this.
public String NVarCharColumn { get { return _NVarCharColumn; } set { if (Object.Equals(value, _NVarCharColumn)) return; _NVarCharColumn = value; this.OnPropertyChanged(); } }
I suggest property template feature in C#6.0. We can declare property template like this.
public property T MyObservableProperty { get { return field; } set { if (Object.Equals(value, field)) return; field = value; this.OnPropertyChanged(); }
void OnPropertyChanged();
}
field is a keyword that means private field generated automatically by compiler.
T means a type that is used by this property.
And the class that use MyObservableProperty must have a method that signature is void OnPropertyChanged().
And we can use it in class like this.
public class Person { property MyObservableProperty String Name; property MyObservableProperty Int32 Age; property MyObservableProperty Boolean IsMan; pulbic void OnPropertyChanged(){...}
}
Above class will be compiled like this.
public class Person { public String Name { get { return _Name; } set { if (Object.Equals(value, _Name)) return; _Name = value; this.OnPropertyChanged(); } } public Int32 Age { get { return _Age; } set { if (Object.Equals(value, _Age)) return; _Age = value; this.OnPropertyChanged(); } } public Boolean IsMan { get { return _IsMan; } set { if (Object.Equals(value, _IsMan)) return; _IsMan = value; this.OnPropertyChanged(); } } pulbic void OnPropertyChanged(){...} }
I hope this feature will be included in C#6.0.
Is it possible?