wabbajack/Wabbajack/ViewModel.cs
Justin Swanson 7b005a1c54 ViewModel class /w RaiseAndSetIfChanged
Made a common base class that implements INotifyPropertyChanged.  Also implements a RaiseAndSetIfChanged call that streamlines property definitions.  Some other various cleaning
2019-10-09 18:41:05 -05:00

31 lines
856 B
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Wabbajack
{
public class ViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
protected void RaiseAndSetIfChanged<T>(
ref T item,
T newItem,
[CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(item, newItem)) return;
item = newItem;
this.RaisePropertyChanged(propertyName);
}
}
}