73 lines
3.5 KiB
C#
73 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WeldingCommon.Utils.Diff
|
|
{
|
|
public static class CompareHelper
|
|
{
|
|
public sealed class FieldSpec<T>
|
|
{
|
|
public string Name { get; }
|
|
public Func<T, object> Getter { get; }
|
|
public Func<object, string> Formatter { get; }
|
|
|
|
public FieldSpec(string name, Func<T, object> getter, Func<object, string> formatter = null)
|
|
{
|
|
Name = name;
|
|
Getter = getter;
|
|
Formatter = formatter;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 지정한 항목만 비교해서, 달라진 것만 diffs에 쌓음
|
|
/// </summary>
|
|
public static void Fill<T>(T oldObj, T newObj, ObservableCollection<PropertyDiff> diffs, params FieldSpec<T>[] fields)
|
|
{
|
|
if (oldObj == null) throw new ArgumentNullException(nameof(oldObj));
|
|
if (newObj == null) throw new ArgumentNullException(nameof(newObj));
|
|
if (diffs == null) throw new ArgumentNullException(nameof(diffs));
|
|
if (fields == null) throw new ArgumentNullException(nameof(fields));
|
|
|
|
diffs.Clear();
|
|
|
|
for (int i = 0; i < fields.Length; i++) {
|
|
var f = fields[i];
|
|
var oldVal = f.Getter(oldObj);
|
|
var newVal = f.Getter(newObj);
|
|
|
|
if (!Equals(oldVal, newVal))
|
|
diffs.Add(new PropertyDiff(f.Name, oldVal, newVal, f.Formatter));
|
|
}
|
|
}
|
|
|
|
/*
|
|
단위 테스트 자료
|
|
//Compare 추가
|
|
var diffs = new ObservableCollection<PropertyDiff>();
|
|
CompareHelper.Fill(RecipeBeforeChangedStageA, RecipeStageA, diffs,
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.N2PressMFC), x => x.N2PressMFC),
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.AxisZPosition), x => x.AxisZPosition),
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.StraightParam.Velocity), x => x.StraightParam.Velocity),
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.CurveParam.Velocity), x => x.CurveParam.Velocity),
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.StraightParam.CorePowerW), x => x.StraightParam.CorePowerW),
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.StraightParam.RingPowerW), x => x.StraightParam.RingPowerW),
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.CurveParam.CorePowerW), x => x.CurveParam.CorePowerW),
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.RampingOnStartPower), x => x.RampingOnStartPower),
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.RampingOnOverlapDist), x => x.RampingOnOverlapDist),
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.RampingOffEndPower), x => x.RampingOffEndPower),
|
|
new CompareHelper.FieldSpec<MainRecipe>(nameof(MainRecipe.RampingOffOverlapDist), x => x.RampingOffOverlapDist)
|
|
);
|
|
if(diffs.Count > 0) {
|
|
Log.FuncI("Recipe Parameter Changed");
|
|
foreach (var diff in diffs)
|
|
Log.V($"{diff.ToString()}");
|
|
}
|
|
*/
|
|
}
|
|
}
|