58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using System;
|
|
using ln.objects.catalog;
|
|
namespace ln.types.odb.ng.diff
|
|
{
|
|
public abstract class Diff
|
|
{
|
|
|
|
public abstract ODBEntity Apply(ODBEntity src);
|
|
|
|
public static Diff Construct(ODBEntity src,ODBEntity dst)
|
|
{
|
|
if (!src.GetType().Equals(dst.GetType()))
|
|
{
|
|
return new SimpleDiff(dst);
|
|
}
|
|
else if (src is Document)
|
|
{
|
|
return new DocumentDiff(src as Document, dst as Document);
|
|
} else if (src is ODBList)
|
|
{
|
|
return new ListDiff(src as ODBList, dst as ODBList);
|
|
}
|
|
|
|
return new SimpleDiff(dst);
|
|
}
|
|
|
|
public string TreeString => ToTreeString(0);
|
|
public abstract string ToTreeString(int indent);
|
|
|
|
|
|
class SimpleDiff : Diff
|
|
{
|
|
public ODBEntity DestinationValue { get; }
|
|
|
|
public SimpleDiff(ODBEntity dst)
|
|
{
|
|
DestinationValue = dst;
|
|
}
|
|
|
|
public override ODBEntity Apply(ODBEntity src)
|
|
{
|
|
return DestinationValue;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return String.Format("[SimpleDiff DestinationValue={0}]",DestinationValue);
|
|
}
|
|
|
|
public override string ToTreeString(int indent)
|
|
{
|
|
return String.Format("= {0}", DestinationValue.ToTreeString(indent+2));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|