Support for boolean uniform-args

This commit is contained in:
benbierens 2023-07-11 10:10:47 +02:00
parent cccf9e426c
commit 76dfd7a86c
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
1 changed files with 9 additions and 0 deletions

View File

@ -194,12 +194,21 @@ namespace ArgsUniform
{
if (uniformProperty.PropertyType == typeof(int?)) return AssignOptionalInt(result, uniformProperty, value);
if (uniformProperty.PropertyType.IsEnum) return AssignEnum(result, uniformProperty, value);
if (uniformProperty.PropertyType == typeof(bool)) return AssignBool(result, uniformProperty, value);
throw new NotSupportedException();
}
}
}
private bool AssignBool(T result, PropertyInfo uniformProperty, object value)
{
var s = value.ToString()!.ToLowerInvariant();
var isTrue = (s == "1" || s == "true");
uniformProperty.SetValue(result, isTrue);
return true;
}
private static bool AssignEnum(T result, PropertyInfo uniformProperty, object value)
{
var s = value.ToString();