From 76dfd7a86ca4c06cf92069b1a847b786e4bb1553 Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 11 Jul 2023 10:10:47 +0200 Subject: [PATCH] Support for boolean uniform-args --- ArgsUniform/ArgsUniform.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ArgsUniform/ArgsUniform.cs b/ArgsUniform/ArgsUniform.cs index 7d58cf1e..a53eee6a 100644 --- a/ArgsUniform/ArgsUniform.cs +++ b/ArgsUniform/ArgsUniform.cs @@ -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();