diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-04-19 18:41:14 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-04-19 18:41:14 -0500 |
| commit | 19d8070d6ce046f8dd3aecd34b30077fbfe6c29d (patch) | |
| tree | 03a3ea256ba2d9681419caa05a024844fe8ded68 | |
| parent | 2c333c74207fe28fd971002ee15620dcf266d2ac (diff) | |
| download | slskd-19d8070d6ce046f8dd3aecd34b30077fbfe6c29d.tar.gz | |
handle nulls in DiffWith
| -rw-r--r-- | src/slskd/Common/CommonExtensions.cs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index 88e6d3c8..1cdf9854 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -116,6 +116,16 @@ namespace slskd 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) + { + return []; + } + + return [(null, parentFqn ?? string.Empty, left, right)]; + } + var differences = new List<(PropertyInfo Property, string FQN, object Left, object Right)>(); foreach (var prop in left?.GetType().GetProperties()) @@ -125,6 +135,16 @@ namespace slskd var propType = prop.PropertyType; var fqn = string.IsNullOrEmpty(parentFqn) ? prop.Name : string.Join(".", parentFqn, prop.Name); + if (leftVal is null || rightVal is null) + { + if (leftVal is null == rightVal is null) + { + continue; + } + + differences.Add((prop, fqn, leftVal, rightVal)); + } + if (propType.IsArray || (propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof(Dictionary<,>))) { if (leftVal.ToJson() != rightVal.ToJson()) |
