aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/CommonExtensions.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-04-24 09:44:44 -0500
committerJP Dillingham <jp@dillingham.me>2026-04-24 09:44:44 -0500
commit64fb4c12a013ed1b50ddcf57fb4bd16decb928f0 (patch)
tree3d647cf4f912fa6437e0d0030e99f577e6f0a2c7 /src/slskd/Common/CommonExtensions.cs
parent19fba8293b472939d74ed23232577cbfdf523586 (diff)
parentfc722e4a78aa5369fcd5ca0d8e88bd98d874a1d8 (diff)
downloadslskd-64fb4c12a013ed1b50ddcf57fb4bd16decb928f0.tar.gz
Merge remote-tracking branch 'origin/master' into retries
Diffstat (limited to 'src/slskd/Common/CommonExtensions.cs')
-rw-r--r--src/slskd/Common/CommonExtensions.cs72
1 files changed, 54 insertions, 18 deletions
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs
index 11d419b4..77db91ef 100644
--- a/src/slskd/Common/CommonExtensions.cs
+++ b/src/slskd/Common/CommonExtensions.cs
@@ -1,18 +1,33 @@
-// <copyright file="CommonExtensions.cs" company="slskd Team">
-// Copyright (c) slskd Team. All rights reserved.
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published
-// by the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see https://www.gnu.org/licenses/.
+// <copyright file="CommonExtensions.cs" company="JP Dillingham">
+// ▄▄▄▄ ▄▄▄▄ ▄▄▄▄
+// ▄▄▄▄▄▄█ █▄▄▄▄▄█ █▄▄▄▄▄█ █
+// █__ --█ █__ --█ ◄█ - █
+// █▄▄▄▄▄█▄▄█▄▄▄▄▄█▄▄█▄▄█▄▄▄▄▄█
+// ┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━━ ━ ━┉ ┉ ┉
+// │ Copyright (c) JP Dillingham.
+// │
+// │ This program is free software: you can redistribute it and/or modify
+// │ it under the terms of the GNU Affero General Public License as published
+// │ by the Free Software Foundation, version 3.
+// │
+// │ This program is distributed in the hope that it will be useful,
+// │ but WITHOUT ANY WARRANTY; without even the implied warranty of
+// │ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// │ GNU Affero General Public License for more details.
+// │
+// │ You should have received a copy of the GNU Affero General Public License
+// │ along with this program. If not, see https://www.gnu.org/licenses/.
+// │
+// │ This program is distributed with Additional Terms pursuant to Section 7
+// │ of the AGPLv3. See the LICENSE file in the root directory of this
+// │ project for the complete terms and conditions.
+// │
+// │ https://slskd.org
+// │
+// ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ╌ ╌╌╌╌ ╌
+// │ SPDX-FileCopyrightText: JP Dillingham
+// │ SPDX-License-Identifier: AGPL-3.0-only
+// ╰───────────────────────────────────────────╶──── ─ ─── ─ ── ──┈ ┈
// </copyright>
namespace slskd
@@ -96,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())