diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-07-27 08:53:18 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-27 08:53:18 -0500 |
| commit | 69d29c1eaa03992cf786d1d9b1ec1935dd85ef42 (patch) | |
| tree | 5253fcd096de96c3bf8c1cd3a9af0f303f4cb41f /src/slskd/Common/Extensions.cs | |
| parent | 58bc401dab5d7eb3bc6cb07a22e0ee9c97ddf4bd (diff) | |
| parent | c5a23135f01697e5fb234988a314be57c9e245d5 (diff) | |
| download | slskd-69d29c1eaa03992cf786d1d9b1ec1935dd85ef42.tar.gz | |
Merge pull request #130 from slskd/lists
Accept option lists via command line and environment variables
Diffstat (limited to 'src/slskd/Common/Extensions.cs')
| -rw-r--r-- | src/slskd/Common/Extensions.cs | 33 |
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)) { |
