mirror of
https://github.com/sp-tarkov/launcher.git
synced 2025-02-13 07:10:44 -05:00
loyvsc
441fb128fe
- NotifyPropertyChangedBase created and implemented in classes that inherit INotifyPropertyChangedBase - Some optimization fixes in models (one of this - `Where(predicate).Count() == 0` to `All(invertedPredicate)` Co-authored-by: Valery Varaksa <varaksav62@gmail.com> Reviewed-on: SPT/Launcher#66 Co-authored-by: loyvsc <loyvsc@noreply.dev.sp-tarkov.com> Co-committed-by: loyvsc <loyvsc@noreply.dev.sp-tarkov.com>
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace SPT.Launcher.Utilities;
|
|
|
|
public abstract class NotifyPropertyChangedBase : INotifyPropertyChanged
|
|
{
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
protected void RaisePropertyChanged(string propertyName)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
protected void SetProperty<T>(ref T field, T value, Action afterSetAction = null, [CallerMemberName] string propertyName = null)
|
|
{
|
|
if (!EqualityComparer<T>.Default.Equals(field, value))
|
|
{
|
|
field = value;
|
|
RaisePropertyChanged(propertyName);
|
|
afterSetAction?.Invoke();
|
|
}
|
|
}
|
|
|
|
protected void SetNotNullableProperty<T>(ref T field, T value, Action afterSetAction = null, [CallerMemberName] string propertyName = null)
|
|
{
|
|
if (value is not null)
|
|
{
|
|
SetProperty(ref field, value, afterSetAction, propertyName );
|
|
}
|
|
}
|
|
} |