Skip to content

Commit bb9e46b

Browse files
committed
avoid code duplications
1 parent ec7dd18 commit bb9e46b

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

Src/FluentAssertions.Json/Common/JTokenExtensions.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,10 @@ private static int Compare(JObject x, JObject y)
7070
if (countComparison != 0)
7171
return countComparison;
7272

73-
var xProperties = x.Properties().OrderBy(p => p.Name).ToArray();
74-
var yProperties = y.Properties().OrderBy(p => p.Name).ToArray();
75-
76-
for (var i = 0; i < xProperties.Length; i++)
77-
{
78-
var nameComparison = string.Compare(xProperties[i].Name, yProperties[i].Name, StringComparison.Ordinal);
79-
if (nameComparison != 0)
80-
return nameComparison;
81-
82-
var valueComparison = Comparer.Compare(xProperties[i].Value, yProperties[i].Value);
83-
if (valueComparison != 0)
84-
return valueComparison;
85-
}
86-
87-
return 0;
73+
return x.Properties()
74+
.OrderBy(p => p.Name)
75+
.Zip(y.Properties().OrderBy(p => p.Name), (px, py) => Compare(px, py))
76+
.FirstOrDefault(itemComparison => itemComparison != 0);
8877
}
8978

9079
private static int Compare(JProperty x, JProperty y)

0 commit comments

Comments
 (0)