aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-11-05 08:24:56 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-11-05 08:24:56 -0500
commita79b0b20e576fde74067614c48398586e7eeb958 (patch)
tree2c1d5925a47360806bc4b4ffa23276ca676ccf73 /src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
parentc97abdba209bc96886b28b6cb4bdd5886ed3de33 (diff)
downloadslskd-a79b0b20e576fde74067614c48398586e7eeb958.tar.gz
bump dependencies
Diffstat (limited to 'src/slskd/Common/Configuration/CommandLineConfigurationSource.cs')
-rw-r--r--src/slskd/Common/Configuration/CommandLineConfigurationSource.cs53
1 files changed, 25 insertions, 28 deletions
diff --git a/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs b/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
index 0436c922..96d8d623 100644
--- a/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
+++ b/src/slskd/Common/Configuration/CommandLineConfigurationSource.cs
@@ -111,45 +111,42 @@ namespace slskd.Configuration
var longName = (string)attribute.ConstructorArguments[1].Value;
var arguments = new[] { shortName, longName }.Where(i => !string.IsNullOrEmpty(i));
- foreach (var argument in arguments)
+ foreach (var argument in arguments.Where(argument => dictionary.ContainsKey(argument)))
{
- if (dictionary.ContainsKey(argument))
+ // if the backing type is an array, it supports multiple values.
+ if (property.PropertyType.IsArray)
{
- // if the backing type is an array, it supports multiple values.
- if (property.PropertyType.IsArray)
- {
- var value = dictionary[argument];
+ var value = dictionary[argument];
- // Parse() will stuff multiple values into a List<T> if the argument name is
- // in the list of those supporting multiple values, and more than one value was supplied.
- // detect this, and add the values to the target.
- if (value.GetType().IsGenericType && value.GetType().GetGenericTypeDefinition() == typeof(List<>))
- {
- var elements = (List<object>)dictionary[argument];
+ // Parse() will stuff multiple values into a List<T> if the argument name is
+ // in the list of those supporting multiple values, and more than one value was supplied.
+ // detect this, and add the values to the target.
+ if (value.GetType().IsGenericType && value.GetType().GetGenericTypeDefinition() == typeof(List<>))
+ {
+ var elements = (List<object>)dictionary[argument];
- for (int i = 0; i < elements.Count; i++)
- {
- Data[ConfigurationPath.Combine(key, i.ToString())] = elements[i].ToString();
- }
- }
- else
+ for (int i = 0; i < elements.Count; i++)
{
- // there may have only been one value supplied, in which case the value is just a
- // string. stick it in index 0 of the target.
- Data[ConfigurationPath.Combine(key, "0")] = value.ToString();
+ Data[ConfigurationPath.Combine(key, i.ToString())] = elements[i].ToString();
}
}
else
{
- var value = dictionary[argument].ToString();
-
- if (property.PropertyType == typeof(bool) && string.IsNullOrEmpty(value))
- {
- value = "true";
- }
+ // there may have only been one value supplied, in which case the value is just a
+ // string. stick it in index 0 of the target.
+ Data[ConfigurationPath.Combine(key, "0")] = value.ToString();
+ }
+ }
+ else
+ {
+ var value = dictionary[argument].ToString();
- Data[key] = value;
+ if (property.PropertyType == typeof(bool) && string.IsNullOrEmpty(value))
+ {
+ value = "true";
}
+
+ Data[key] = value;
}
}
}