diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-04-19 18:50:28 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-04-19 18:50:28 -0500 |
| commit | d415e5ca568f55cf9c45e84b05892219f9e1465a (patch) | |
| tree | c20ef4f32d9b810faf02d264eda9b0ad4037238f /src | |
| parent | 8ef80b442688288a40fb8c8fa8392249dc6ebb10 (diff) | |
| download | slskd-d415e5ca568f55cf9c45e84b05892219f9e1465a.tar.gz | |
check for nulls first
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/CommonExtensions.cs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index 1cdf9854..77db91ef 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -111,11 +111,6 @@ namespace slskd /// <returns>A list of differences between the two objects.</returns> public static IEnumerable<(PropertyInfo Property, string FQN, object Left, object Right)> DiffWith(this object left, object right, string parentFqn = null) { - if (left?.GetType() != right?.GetType()) - { - throw new InvalidCastException($"Unable to diff types {left?.GetType()} and {right?.GetType()}"); - } - if (left is null || right is null) { if (left is null == right is null) @@ -126,9 +121,14 @@ namespace slskd return [(null, parentFqn ?? string.Empty, left, right)]; } + if (left.GetType() != right.GetType()) + { + throw new InvalidCastException($"Unable to diff types {left.GetType()} and {right.GetType()}"); + } + var differences = new List<(PropertyInfo Property, string FQN, object Left, object Right)>(); - foreach (var prop in left?.GetType().GetProperties()) + foreach (var prop in left.GetType().GetProperties()) { var leftVal = prop.GetValue(left); var rightVal = prop.GetValue(right); @@ -143,6 +143,7 @@ namespace slskd } differences.Add((prop, fqn, leftVal, rightVal)); + continue; } if (propType.IsArray || (propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof(Dictionary<,>))) |
