Files
PowerToys/src/settings-ui/Settings.UI/Helpers/Observable.cs

28 lines
871 B
C#
Raw Normal View History

// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
2020-03-11 10:43:32 -07:00
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Microsoft.PowerToys.Settings.UI.Helpers
{
public class Observable : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void Set<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
2020-03-11 10:43:32 -07:00
{
if (Equals(storage, value))
{
return;
}
storage = value;
OnPropertyChanged(propertyName);
2020-03-11 10:43:32 -07:00
}
protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
2020-03-11 10:43:32 -07:00
}
}