Skip to content

Instantly share code, notes, and snippets.

@reniris
Last active May 15, 2018 12:45
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 reniris/e68089c80df076ac6705340e2bb63597 to your computer and use it in GitHub Desktop.
Save reniris/e68089c80df076ac6705340e2bb63597 to your computer and use it in GitHub Desktop.
インデクサをIObservable<T>に変更する拡張メソッド
public static class PropertyChangedExtensions
{
public static IObservable<PropertyChangedEventArgs> ObserveIndexer(this INotifyPropertyChanged self, string indexerName = "Item")
{
return Observable.FromEvent<PropertyChangedEventHandler, PropertyChangedEventArgs>(
h => (s, e) => h(e),
h => self.PropertyChanged += h,
h => self.PropertyChanged -= h)
.Where(e => e.PropertyName == indexerName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment