From fd9b126b712ed1c83577257cc9b5781cfb3e012a Mon Sep 17 00:00:00 2001 From: Felix-CodingClimber Date: Sat, 6 Apr 2024 07:02:16 +0200 Subject: [PATCH] Fixed bug when serializing DiffPiece. --- .../Core/StringDiff/DiffBuilder/Model/DiffPiece.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/DotNetElements.Core/Core/StringDiff/DiffBuilder/Model/DiffPiece.cs b/src/DotNetElements.Core/Core/StringDiff/DiffBuilder/Model/DiffPiece.cs index 241d6f5..3650359 100644 --- a/src/DotNetElements.Core/Core/StringDiff/DiffBuilder/Model/DiffPiece.cs +++ b/src/DotNetElements.Core/Core/StringDiff/DiffBuilder/Model/DiffPiece.cs @@ -1,4 +1,6 @@ -namespace DotNetElements.Core.StringDiff; +using System.Text.Json.Serialization; + +namespace DotNetElements.Core.StringDiff; public enum ChangeType { @@ -12,5 +14,13 @@ public enum ChangeType public record struct DiffPiece(string? Text, ChangeType Type, int? PositionOld = null, int? PositionNew = null) { public List SubPieces { get; private init; } = []; - public bool IsOldPiece { get; set; } + public bool IsOldPiece { get; init; } + + [JsonConstructor] + public DiffPiece(string? text, ChangeType type, int? positionOld, int? positionNew, List subPieces, bool isOldPiece) : + this(text, type, positionOld, positionNew) + { + SubPieces = subPieces; + IsOldPiece = isOldPiece; + } } \ No newline at end of file