From 38fffb41095432448b87b42a1ed8300dc74ba2d9 Mon Sep 17 00:00:00 2001 From: Albie Date: Fri, 30 Dec 2022 11:11:18 +0000 Subject: [PATCH] trim spaces when converting flags to a string --- src/Utils/ParameterUtils.cs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Utils/ParameterUtils.cs b/src/Utils/ParameterUtils.cs index d6123f8..0c1e96f 100644 --- a/src/Utils/ParameterUtils.cs +++ b/src/Utils/ParameterUtils.cs @@ -61,17 +61,26 @@ internal static IEnumerable> GetParameter(object yield return entry; } } - else if (property.PropertyType.IsEnum && attribute.EnumHandling.HasValue) + else if (property.PropertyType.IsEnum) { - yield return attribute.EnumHandling.Value switch + switch (attribute.EnumHandling) { - EnumHandlingMode.Numeric => ((int)propertyValue).ToKeyValuePair(keyName, culture), - EnumHandlingMode.StringLower => propertyValue.ToString().ToLower(culture).ToKeyValuePair(keyName, culture), - EnumHandlingMode.StringUpper => propertyValue.ToString().ToUpper(culture).ToKeyValuePair(keyName, culture), + case EnumHandlingMode.Numeric: + yield return ((int)propertyValue).ToKeyValuePair(keyName, culture); + break; - // default includes string handling - _ => propertyValue.ToKeyValuePair(keyName, culture) - }; + case EnumHandlingMode.StringLower: + yield return propertyValue.ToString().ToLower(culture).Replace(" ", string.Empty).ToKeyValuePair(keyName, culture); + break; + + case EnumHandlingMode.StringUpper: + yield return propertyValue.ToString().ToUpper(culture).Replace(" ", string.Empty).ToKeyValuePair(keyName, culture); + break; + + case null: + yield return propertyValue.ToKeyValuePair(keyName, culture); + break; + } } else {