51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using Aurora.View;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WeldingCommon.Utils.Diff
|
|
{
|
|
public sealed class PropertyDiff : NotifyPropertyChangedBase
|
|
{
|
|
|
|
public string Name { get => _name; set => SetProperty(ref _name, value); }
|
|
private string _name;
|
|
|
|
public object OldValue { get => _oldValue; set => SetProperty(ref _oldValue, value); }
|
|
private object _oldValue;
|
|
|
|
public object NewValue { get => _newValue; set => SetProperty(ref _newValue, value); }
|
|
private object _newValue;
|
|
|
|
public string OldText { get => _oldText; set => SetProperty(ref _oldText, value); }
|
|
private string _oldText;
|
|
|
|
public string NewText { get => _newText; set => SetProperty(ref _newText, value); }
|
|
private string _newText;
|
|
|
|
public PropertyDiff(string name, object oldValue, object newValue, Func<object, string> formatter = null)
|
|
{
|
|
_name = name ?? "";
|
|
_oldValue = oldValue;
|
|
_newValue = newValue;
|
|
|
|
var fmt = formatter ?? DefaultFormat;
|
|
_oldText = fmt(oldValue);
|
|
_newText = fmt(newValue);
|
|
}
|
|
|
|
private static string DefaultFormat(object v)
|
|
{
|
|
if (v == null) return "(null)";
|
|
if (v is DateTime dt) return dt.ToString("yyyy-MM-dd HH:mm:ss");
|
|
return v.ToString();
|
|
}
|
|
|
|
public override string ToString()
|
|
=> $"{Name}: {OldText} -> {NewText}";
|
|
}
|
|
}
|