From 3525772a48c36e9b18c02323e5091a9f9dc23360 Mon Sep 17 00:00:00 2001 From: Marko Urh Date: Fri, 16 Jun 2023 09:31:01 +0200 Subject: [PATCH] Bugfix/path set minor (#4) * fix: dry path set --- source/Directory.Build.props | 2 +- source/Perun.Differ/Models.cs | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/source/Directory.Build.props b/source/Directory.Build.props index e9d5b54..9fc696d 100644 --- a/source/Directory.Build.props +++ b/source/Directory.Build.props @@ -1,7 +1,7 @@ - 2.0.1 + 2.0.2 Marko Urh Perun Copyright (c) 2023 Marko Urh and other authors. diff --git a/source/Perun.Differ/Models.cs b/source/Perun.Differ/Models.cs index bfbdfd2..9ab4825 100644 --- a/source/Perun.Differ/Models.cs +++ b/source/Perun.Differ/Models.cs @@ -20,26 +20,34 @@ public sealed class Difference public string CustomFieldPath { get; set; } public string CustomFieldName { get; set; } + public Difference() + { + } + public Difference(string fullPath, string customFullPath, object leftValue, object rightValue) { - FullPath = fullPath; - - var fullPathSplit = FullPath.Split('.'); - FieldName = FullPath.Split('.').LastOrDefault(); - FieldPath = string.Join(".", fullPathSplit.Take(fullPathSplit.Length - 1)); + LeftValue = leftValue; + RightValue = rightValue; - if (fullPath != customFullPath) + (FullPath, FieldName, FieldPath) = SetPath(fullPath); + if (fullPath != customFullPath && customFullPath != null) { - CustomFullPath = customFullPath; - - var customSplit = CustomFullPath.Split('.'); + (CustomFullPath, CustomFieldName, CustomFieldPath) = SetPath(customFullPath); + } + } - CustomFieldName = CustomFullPath.Split('.').LastOrDefault(); - CustomFieldPath = string.Join(".", customSplit.Take(customSplit.Length - 1)); + private (string, string, string) SetPath(string fullPath) + { + if (fullPath == null) + { + return (null, null, null); } - LeftValue = leftValue; - RightValue = rightValue; + var pathSplit = fullPath.Split('.'); + var fieldName = pathSplit.LastOrDefault(); + var fieldPath = string.Join(".", pathSplit.Take(pathSplit.Length - 1)); + + return (fullPath, fieldName, fieldPath); } } } \ No newline at end of file