diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-04-23 18:29:09 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-04-23 18:29:09 -0500 |
| commit | 2f20ac833dca19e87e7980ac83f94206685409d9 (patch) | |
| tree | 1ebad506bc42f3bc20e6825bf9f03715031c06ba /src | |
| parent | 3d9bc65bf535a3c4dab440e91587495afba648e6 (diff) | |
| parent | 7961741f740abd240754ff6e39cda6d69f727268 (diff) | |
| download | slskd-2f20ac833dca19e87e7980ac83f94206685409d9.tar.gz | |
Merge remote-tracking branch 'origin/master' into blacklist-regex
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Common/CommonExtensions.cs | 27 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 814e01a3..e36a5539 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -1459,7 +1459,7 @@ namespace slskd foreach (var (property, fqn, left, right) in diff) { - static bool HasAttribute<T>(PropertyInfo property) => property.CustomAttributes.Any(a => a.AttributeType == typeof(T)); + static bool HasAttribute<T>(PropertyInfo property) => property?.CustomAttributes.Any(a => a.AttributeType == typeof(T)) ?? false; var requiresRestart = HasAttribute<RequiresRestartAttribute>(property); var requiresReconnect = HasAttribute<RequiresReconnectAttribute>(property); diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index 88e6d3c8..77db91ef 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -111,20 +111,41 @@ 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()) + if (left is null || right is null) { - throw new InvalidCastException($"Unable to diff types {left?.GetType()} and {right?.GetType()}"); + if (left is null == right is null) + { + return []; + } + + 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); 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)); + continue; + } + if (propType.IsArray || (propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof(Dictionary<,>))) { if (leftVal.ToJson() != rightVal.ToJson()) |
