Created
January 29, 2018 14:16
-
-
Save azyobuzin/3784560cc91feb161a28b1a6cd6f0c05 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/// <summary> | |
/// <see cref="DependencyOnModelPropertyAttribute"/> が指定されたプロパティの変更通知を有効化します。 | |
/// </summary> | |
protected void EnableAutoPropertyChangedEvent(INotifyPropertyChanged model) | |
{ | |
PropertyChangedEventListener listener = null; | |
foreach (var prop in this.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) | |
{ | |
PropertyChangedEventHandler handler = null; | |
foreach (var attr in prop.GetCustomAttributes<DependencyOnModelPropertyAttribute>()) | |
{ | |
if (listener == null) listener = new PropertyChangedEventListener(model); | |
if (handler == null) handler = CreateHandler(prop.Name); | |
listener.Add(attr.DependentPropertyName, handler); | |
} | |
} | |
if (listener != null) this.CompositeDisposable.Add(listener); | |
PropertyChangedEventHandler CreateHandler(string propertyName) => (_, __) => this.RaisePropertyChanged(propertyName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment