2019-03-29 19:52:57 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Utilities
|
|
|
|
|
{
|
|
|
|
|
public abstract class ExtendedViewModel : INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
2019-03-29 23:52:57 +03:00
|
|
|
|
protected bool SetProperty<T>(ref T backingStore, T value, Action onChanged = null,
|
2019-04-26 07:26:09 +03:00
|
|
|
|
[CallerMemberName] string propertyName = "", string[] additionalPropertyNames = null)
|
2019-03-29 19:52:57 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (EqualityComparer<T>.Default.Equals(backingStore, value))
|
2019-03-29 19:52:57 +03:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
backingStore = value;
|
2019-05-08 21:37:12 +03:00
|
|
|
|
TriggerPropertyChanged(propertyName, additionalPropertyNames);
|
|
|
|
|
onChanged?.Invoke();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void TriggerPropertyChanged(string propertyName, string[] additionalPropertyNames = null)
|
|
|
|
|
{
|
2019-03-29 23:52:57 +03:00
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
2020-03-28 16:16:28 +03:00
|
|
|
|
if (PropertyChanged != null && additionalPropertyNames != null)
|
2019-04-26 07:26:09 +03:00
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
|
foreach (var prop in additionalPropertyNames)
|
2019-04-26 07:26:09 +03:00
|
|
|
|
{
|
|
|
|
|
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(prop));
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-29 19:52:57 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|