Skip to content

Commit

Permalink
trim spaces when converting flags to a string
Browse files Browse the repository at this point in the history
  • Loading branch information
aspriddell committed Dec 30, 2022
1 parent 94bd4c0 commit 38fffb4
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/Utils/ParameterUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,26 @@ internal static IEnumerable<KeyValuePair<string, string>> GetParameter<T>(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
{
Expand Down

0 comments on commit 38fffb4

Please sign in to comment.