Files
Libation/Source/LibationUiBase/ReactiveObject.cs
MBucari e850465ec1 Add more null safety
Enable project-wide nullable on LibationUiBase and LibationAvalonia

Explicitly parallelize unit tests
2025-12-30 13:17:11 -07:00

39 lines
1.5 KiB
C#

using Dinah.Core.Threading;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace LibationUiBase;
/// <summary>
/// ReactiveObject is the base object for ViewModel classes, and it implements INotifyPropertyChanging
/// and INotifyPropertyChanged. Additionally
/// object changes.
/// </summary>
public class ReactiveObject : SynchronizeInvoker, INotifyPropertyChanged, INotifyPropertyChanging
{
// see also notes in Libation/Source/_ARCHITECTURE NOTES.txt :: MVVM
public event PropertyChangedEventHandler? PropertyChanged;
public event PropertyChangingEventHandler? PropertyChanging;
public void RaisePropertyChanging(PropertyChangingEventArgs args) => Invoke(() => PropertyChanging?.Invoke(this, args));
public void RaisePropertyChanging(string propertyName) => RaisePropertyChanging(new PropertyChangingEventArgs(propertyName));
public void RaisePropertyChanged(PropertyChangedEventArgs args) => Invoke(() => PropertyChanged?.Invoke(this, args));
public void RaisePropertyChanged(string propertyName) => RaisePropertyChanged(new PropertyChangedEventArgs(propertyName));
public TRet RaiseAndSetIfChanged<TRet>(ref TRet backingField, TRet newValue, [CallerMemberName] string? propertyName = null)
{
ArgumentException.ThrowIfNullOrWhiteSpace(propertyName, nameof(propertyName));
if (!EqualityComparer<TRet>.Default.Equals(backingField, newValue))
{
RaisePropertyChanging(propertyName);
backingField = newValue;
RaisePropertyChanged(propertyName!);
}
return newValue;
}
}