From e4a7073ea750c6bf3a82b35b81ba3883f8438fb4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 26 Jul 2021 22:57:02 -0500 Subject: add GetPropertiesRecursively extension --- src/slskd/Common/Extensions.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/slskd/Common/Extensions.cs') diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 3e4f6e68..33faecf7 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -44,6 +44,30 @@ namespace slskd /// The new object deserialzied from the string. public static T ToObject(this string str) => JsonSerializer.Deserialize(str); + /// + /// Recursively retrieves all properties. + /// + /// The type from which to retrieve properties. + /// The list of properties. + public static IEnumerable GetPropertiesRecursively(this Type type) + { + var props = new List(); + + 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; + } + /// /// Deeply compares this object with the specified object and returns a list of properties that are different. /// -- cgit v1.2.3 From 281da1abdb3e8496142a37dcff57376e9672cf31 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 27 Jul 2021 07:46:38 -0500 Subject: handle arrays in DiffWith (#129) --- src/slskd/Common/Extensions.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/slskd/Common/Extensions.cs') diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 33faecf7..51c0d147 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -91,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)) { -- cgit v1.2.3