wabbajack/Wabbajack.App.Wpf/ViewModel.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2021-12-26 21:56:44 +00:00
using Newtonsoft.Json;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Reactive.Disposables;
using System.Runtime.CompilerServices;
using Wabbajack.Models;
2021-12-26 21:56:44 +00:00
2021-12-30 00:15:37 +00:00
namespace Wabbajack
2021-12-26 21:56:44 +00:00
{
public class ViewModel : ReactiveObject, IDisposable, IActivatableViewModel
2021-12-26 21:56:44 +00:00
{
private readonly Lazy<CompositeDisposable> _compositeDisposable = new();
2021-12-26 21:56:44 +00:00
[JsonIgnore]
public CompositeDisposable CompositeDisposable => _compositeDisposable.Value;
[JsonIgnore] public LoadingLock LoadingLock { get; } = new();
2021-12-26 21:56:44 +00:00
public virtual void Dispose()
{
if (_compositeDisposable.IsValueCreated)
{
_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);
}
public ViewModelActivator Activator { get; } = new();
2021-12-26 21:56:44 +00:00
}
}