aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Extensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/slskd/Common/Extensions.cs')
-rw-r--r--src/slskd/Common/Extensions.cs33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs
index 3e4f6e68..51c0d147 100644
--- a/src/slskd/Common/Extensions.cs
+++ b/src/slskd/Common/Extensions.cs
@@ -45,6 +45,30 @@ namespace slskd
public static T ToObject<T>(this string str) => JsonSerializer.Deserialize<T>(str);
/// <summary>
+ /// Recursively retrieves all properties.
+ /// </summary>
+ /// <param name="type">The type from which to retrieve properties.</param>
+ /// <returns>The list of properties.</returns>
+ public static IEnumerable<PropertyInfo> GetPropertiesRecursively(this Type type)
+ {
+ var props = new List<PropertyInfo>();
+
+ foreach (var prop in type.GetProperties())
+ {
+ if (prop.PropertyType.IsPrimitive || prop.PropertyType.IsArray || Nullable.GetUnderlyingType(prop.PropertyType) != null || new[] { typeof(string), typeof(decimal) }.Contains(prop.PropertyType))
+ {
+ props.Add(prop);
+ }
+ else
+ {
+ props.AddRange(prop.PropertyType.GetPropertiesRecursively());
+ }
+ }
+
+ return props;
+ }
+
+ /// <summary>
/// Deeply compares this object with the specified object and returns a list of properties that are different.
/// </summary>
/// <param name="left">The left side of the comparison.</param>
@@ -67,7 +91,14 @@ namespace slskd
var propType = prop.PropertyType;
var fqn = string.IsNullOrEmpty(parentFqn) ? prop.Name : string.Join(".", parentFqn, prop.Name);
- if (propType.IsPrimitive || Nullable.GetUnderlyingType(propType) != null || new[] { typeof(string), typeof(decimal) }.Contains(propType))
+ if (propType.IsArray)
+ {
+ if (leftVal.ToJson() != rightVal.ToJson())
+ {
+ differences.Add((prop, fqn, leftVal, rightVal));
+ }
+ }
+ else if (propType.IsPrimitive || Nullable.GetUnderlyingType(propType) != null || new[] { typeof(string), typeof(decimal) }.Contains(propType))
{
if (!Equals(leftVal, rightVal))
{