0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-13 06:30:43 -05:00
launcher/project/SPT.Launcher.Base/Utilities/NotifyPropertyChangedBase.cs
loyvsc 441fb128fe Implement NotifyPropertyChangedBase, optimization (!66)
- 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>
2024-09-02 07:53:58 +00:00

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 );
}
}
}