Observable.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System.ComponentModel;
 6  using System.Runtime.CompilerServices;
 7  
 8  namespace Microsoft.PowerToys.Settings.UI.Library.Helpers
 9  {
10      public class Observable : INotifyPropertyChanged
11      {
12          public event PropertyChangedEventHandler PropertyChanged;
13  
14          protected bool Set<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
15          {
16              if (Equals(storage, value))
17              {
18                  return false;
19              }
20  
21              storage = value;
22              OnPropertyChanged(propertyName);
23  
24              return true;
25          }
26  
27          protected void OnPropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
28      }
29  }