Skip to content

Commit

Permalink
Bugfix/path set minor (#4)
Browse files Browse the repository at this point in the history
* fix: dry path set
  • Loading branch information
maranmaran authored Jun 16, 2023
1 parent 82fedbf commit 3525772
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion source/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>2.0.1</Version>
<Version>2.0.2</Version>
<Authors>Marko Urh</Authors>
<Company>Perun</Company>
<Copyright>Copyright (c) 2023 Marko Urh and other authors.</Copyright>
Expand Down
34 changes: 21 additions & 13 deletions source/Perun.Differ/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 3525772

Please sign in to comment.