2
0
mirror of synced 2025-02-27 15:30:35 +00:00

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

View File

@ -194,12 +194,21 @@ namespace ArgsUniform
{ {
if (uniformProperty.PropertyType == typeof(int?)) return AssignOptionalInt(result, uniformProperty, value); if (uniformProperty.PropertyType == typeof(int?)) return AssignOptionalInt(result, uniformProperty, value);
if (uniformProperty.PropertyType.IsEnum) return AssignEnum(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(); 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) private static bool AssignEnum(T result, PropertyInfo uniformProperty, object value)
{ {
var s = value.ToString(); var s = value.ToString();