using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace JdeScoping.SecureStoreManager.ViewModels;
///
/// Base class for all view models providing INotifyPropertyChanged implementation.
///
public abstract class ViewModelBase : INotifyPropertyChanged
{
/// Occurs when a property value changes.
public event PropertyChangedEventHandler? PropertyChanged;
///
/// Raises the PropertyChanged event for the specified property.
///
/// The name of the property that changed.
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
///
/// Sets a property value and raises PropertyChanged if the value changed.
///
/// The type of the property.
/// Reference to the backing field.
/// The new value.
/// The name of the property.
/// True if the value changed, false otherwise.
protected bool SetProperty(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer.Default.Equals(field, value))
return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
}