diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-04-09 12:30:18 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-04-09 12:30:18 -0500 |
| commit | 47c70b89be1a13b321e2726e2f4b05af56c67e67 (patch) | |
| tree | b5b7f221ee10cb92e6dcae6634d5dff157be0b8c /src | |
| parent | 63a34dc2fcf3c06a91af5b74dac47ecd2e19f9fa (diff) | |
| download | slskd-47c70b89be1a13b321e2726e2f4b05af56c67e67.tar.gz | |
swallow exceptions raised when trying to traverse primitive types
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Program.cs | 92 |
1 files changed, 53 insertions, 39 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 0857ef4d..bcf1df0a 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -1,4 +1,4 @@ -// <copyright file="Program.cs" company="slskd Team"> +// <copyright file="Program.cs" company="slskd Team"> // Copyright (c) slskd Team. All rights reserved. // // This program is free software: you can redistribute it and/or modify @@ -468,31 +468,38 @@ namespace slskd void Map(Type type) { - var defaults = Activator.CreateInstance(type); - var props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); - - foreach (PropertyInfo property in props) + try { - var attribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(ArgumentAttribute)); - var descriptionAttribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DescriptionAttribute)); - var isRequired = property.CustomAttributes.Any(a => a.AttributeType == typeof(RequiredAttribute)); + var defaults = Activator.CreateInstance(type); + var props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); - if (attribute != default) + foreach (PropertyInfo property in props) { - var shortName = (char)attribute.ConstructorArguments[0].Value; - var longName = (string)attribute.ConstructorArguments[1].Value; - var description = descriptionAttribute?.ConstructorArguments[0].Value; - - var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? "<null>"})"; - var item = $"{(shortName == default ? " " : $"{shortName}|")}--{GetLongName(longName, property.PropertyType)}"; - var desc = $"{description}{(property.PropertyType == typeof(bool) ? string.Empty : suffix)}"; - lines.Add(new(item, desc)); - } - else - { - Map(property.PropertyType); + var attribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(ArgumentAttribute)); + var descriptionAttribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DescriptionAttribute)); + var isRequired = property.CustomAttributes.Any(a => a.AttributeType == typeof(RequiredAttribute)); + + if (attribute != default) + { + var shortName = (char)attribute.ConstructorArguments[0].Value; + var longName = (string)attribute.ConstructorArguments[1].Value; + var description = descriptionAttribute?.ConstructorArguments[0].Value; + + var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? "<null>"})"; + var item = $"{(shortName == default ? " " : $"{shortName}|")}--{GetLongName(longName, property.PropertyType)}"; + var desc = $"{description}{(property.PropertyType == typeof(bool) ? string.Empty : suffix)}"; + lines.Add(new(item, desc)); + } + else + { + Map(property.PropertyType); + } } } + catch + { + return; + } } Map(targetType); @@ -516,30 +523,37 @@ namespace slskd void Map(Type type) { - var defaults = Activator.CreateInstance(type); - var props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); - - foreach (PropertyInfo property in props) + try { - var attribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(EnvironmentVariableAttribute)); - var descriptionAttribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DescriptionAttribute)); - var isRequired = property.CustomAttributes.Any(a => a.AttributeType == typeof(RequiredAttribute)); + var defaults = Activator.CreateInstance(type); + var props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); - if (attribute != default) + foreach (PropertyInfo property in props) { - var name = (string)attribute.ConstructorArguments[0].Value; - var description = descriptionAttribute?.ConstructorArguments[0].Value; + var attribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(EnvironmentVariableAttribute)); + var descriptionAttribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DescriptionAttribute)); + var isRequired = property.CustomAttributes.Any(a => a.AttributeType == typeof(RequiredAttribute)); - var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? "<null>"})"; - var item = $"{prefix}{GetName(name, property.PropertyType)}"; - var desc = $"{description}{(type == typeof(bool) ? string.Empty : suffix)}"; - lines.Add(new(item, desc)); - } - else - { - Map(property.PropertyType); + if (attribute != default) + { + var name = (string)attribute.ConstructorArguments[0].Value; + var description = descriptionAttribute?.ConstructorArguments[0].Value; + + var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? "<null>"})"; + var item = $"{prefix}{GetName(name, property.PropertyType)}"; + var desc = $"{description}{(type == typeof(bool) ? string.Empty : suffix)}"; + lines.Add(new(item, desc)); + } + else + { + Map(property.PropertyType); + } } } + catch + { + return; + } } Map(targetType); |
