43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using ln.types.odb.values;
|
|
using System.Linq;
|
|
namespace ln.types.odb.ng.diff
|
|
{
|
|
public class DocumentDiff : Diff
|
|
{
|
|
Dictionary<ODBEntity, Diff> propertyDiffs = new Dictionary<ODBEntity, Diff>();
|
|
|
|
public DocumentDiff(Document src, Document dst)
|
|
{
|
|
HashSet<ODBEntity> keys = new HashSet<ODBEntity>(src.Keys);
|
|
foreach (ODBEntity key in dst.Keys)
|
|
keys.Add(key);
|
|
|
|
foreach (ODBEntity key in keys)
|
|
{
|
|
if (!src[key].Equals(dst[key]))
|
|
propertyDiffs.Add(key, Diff.Construct(src[key], dst[key]));
|
|
}
|
|
}
|
|
|
|
public override ODBEntity Apply(ODBEntity src)
|
|
{
|
|
Document srcDocument = src as Document;
|
|
|
|
foreach (ODBValue key in propertyDiffs.Keys)
|
|
{
|
|
srcDocument[key] = propertyDiffs[key].Apply(srcDocument[key]);
|
|
}
|
|
|
|
return src;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return String.Format("[DocumentDiff ChangedProperties=({0})]",string.Join(",",propertyDiffs.Keys));
|
|
}
|
|
|
|
}
|
|
}
|