private static DiffOperation DiffValue(Tag first, Tag second) { if (first == null && second == null) { return(null); } else if (second == null) { return(new RemoveOperation()); } else if (first == null) { return(new ChangeOperation(second)); } else if (first.TagType != second.TagType) { return(new ChangeOperation(second)); } else { switch (first.TagType) { case TagType.Byte: case TagType.Short: case TagType.Int: case TagType.Long: case TagType.Float: case TagType.Double: case TagType.String: case TagType.ByteArray: case TagType.IntArray: return(first.DataEqual(second) ? null : new ChangeOperation(second)); case TagType.Compound: CompoundDiff compDiff = Diff(first as TagCompound, second as TagCompound); return(compDiff.IsEmpty ? null : new ChangeObjectOperation(compDiff)); case TagType.List: if (AreIdArrays(first as TagList, second as TagList)) { CompoundDiff subDiff = IdDiff(first as TagList, second as TagList); return(subDiff.IsEmpty ? null : new ChangeIdArrayOperation(subDiff)); } else { ListDiff subDiff = PositionDiff(first as TagList, second as TagList); return(subDiff.IsEmpty ? null : new ChangePositionArrayOperation(subDiff)); } default: throw new Exception("Unexpected tag type"); } } }
private static DiffOperation DiffValue(Tag first, Tag second) { if (first == null && second == null) return null; else if (second == null) return new RemoveOperation(); else if (first == null) return new ChangeOperation(second); else if (first.TagType != second.TagType) return new ChangeOperation(second); else { switch (first.TagType) { case TagType.Byte: case TagType.Short: case TagType.Int: case TagType.Long: case TagType.Float: case TagType.Double: case TagType.String: case TagType.ByteArray: case TagType.IntArray: return first.DataEqual(second) ? null : new ChangeOperation(second); case TagType.Compound: CompoundDiff compDiff = Diff(first as TagCompound, second as TagCompound); return compDiff.IsEmpty ? null : new ChangeObjectOperation(compDiff); case TagType.List: if (AreIdArrays(first as TagList, second as TagList)) { CompoundDiff subDiff = IdDiff(first as TagList, second as TagList); return subDiff.IsEmpty ? null : new ChangeIdArrayOperation(subDiff); } else { ListDiff subDiff = PositionDiff(first as TagList, second as TagList); return subDiff.IsEmpty ? null : new ChangePositionArrayOperation(subDiff); } default: throw new Exception("Unexpected tag type"); } } }