port from perforce
This commit is contained in:
39
intromat/Intromat/ViewModels/UndoItem.cs
Normal file
39
intromat/Intromat/ViewModels/UndoItem.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Intromat.Interfaces;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Intromat.ViewModels
|
||||
{
|
||||
public class UndoItem<TObservable, TValue> : IUndoItem where TObservable : ReactiveObject
|
||||
{
|
||||
private readonly TValue _newValue;
|
||||
private readonly TObservable _observable;
|
||||
private readonly TValue _oldValue;
|
||||
private readonly PropertyInfo _propertyInfo;
|
||||
|
||||
public UndoItem(IFile file, TObservable observable, Expression<Func<TObservable, TValue>> memberLamda, TValue oldValue, TValue newValue)
|
||||
{
|
||||
File = file;
|
||||
_observable = observable;
|
||||
_oldValue = oldValue;
|
||||
_newValue = newValue;
|
||||
if (memberLamda.Body is MemberExpression { Member: PropertyInfo propertyInfo }) _propertyInfo = propertyInfo;
|
||||
Debug.Assert(_propertyInfo != null);
|
||||
}
|
||||
|
||||
public IFile File { get; }
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
_propertyInfo.SetValue(_observable, _newValue);
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
_propertyInfo.SetValue(_observable, _oldValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user