diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-07-27 06:38:39 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-07-27 06:38:39 -0500 |
| commit | 742c8c8a77d28eccda886f0e6ca15d4a05a3cf4d (patch) | |
| tree | 0b7cb4d34aa4a5b9809e503f221062bfa5c95bbb /src/slskd/Common/Extensions.cs | |
| parent | 48d569da0e86f1ec0144713c25cad3a5e767c4d2 (diff) | |
| parent | 2e04802345be5d887e53351dafc13830f38a9cd7 (diff) | |
| download | slskd-742c8c8a77d28eccda886f0e6ca15d4a05a3cf4d.tar.gz | |
Merge branch 'lists' of https://github.com/slskd/slskd into lists
Diffstat (limited to 'src/slskd/Common/Extensions.cs')
| -rw-r--r-- | src/slskd/Common/Extensions.cs | 24 |
1 files changed, 24 insertions, 0 deletions
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 @@ -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> |
