bitwarden-android/src/Core/Utilities/ExtendedViewModel.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
1.3 KiB
C#
Raw Normal View History

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))
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));
if (PropertyChanged != null && additionalPropertyNames != null)
2019-04-26 07:26:09 +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
}
}
}