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
|
|
|
|
{
|
|
|
|
|
if(EqualityComparer<T>.Default.Equals(backingStore, value))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
backingStore = value;
|
2019-03-29 23:52:57 +03:00
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
2019-04-26 07:26:09 +03:00
|
|
|
|
if(PropertyChanged != null && additionalPropertyNames != null)
|
|
|
|
|
{
|
|
|
|
|
foreach(var prop in additionalPropertyNames)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(prop));
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-29 19:52:57 +03:00
|
|
|
|
onChanged?.Invoke();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|