wabbajack/Wabbajack.Lib/ViewModel.cs

35 lines
1003 B
C#
Raw Normal View History

using Newtonsoft.Json;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Reactive.Disposables;
using System.Runtime.CompilerServices;
namespace Wabbajack.Lib
{
public class ViewModel : ReactiveObject, IDisposable
{
2019-11-21 15:51:57 +00:00
private readonly Lazy<CompositeDisposable> _compositeDisposable = new Lazy<CompositeDisposable>();
[JsonIgnore]
2019-11-21 15:51:57 +00:00
public CompositeDisposable CompositeDisposable => _compositeDisposable.Value;
public virtual void Dispose()
{
2019-11-21 15:51:57 +00:00
if (_compositeDisposable.IsValueCreated)
{
2019-11-21 15:51:57 +00:00
_compositeDisposable.Value.Dispose();
}
}
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);
}
}
}