Skip to content

Commit

Permalink
Merge pull request #432 from 0xced/string-to-enum-ignore-case
Browse files Browse the repository at this point in the history
Make string to enum conversion case insensitive
  • Loading branch information
nblumhardt authored Aug 6, 2024
2 parents e42be6a + 47f447a commit 296a8ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public StringArgumentValue(string providedValue)
}

if (toTypeInfo.IsEnum)
return Enum.Parse(toType, argumentValue);
return Enum.Parse(toType, argumentValue, ignoreCase: true);

var convertor = ExtendedTypeConversions
.Where(t => t.Key.GetTypeInfo().IsAssignableFrom(toTypeInfo))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ public void ReferencingUndeclaredLevelSwitchThrows()
Assert.Contains("\"LevelSwitches\":{\"$mySwitch\":", ex.Message);
}

[Fact]
public void StringValuesConvertToEnumByName()
[Theory]
[InlineData("Information")]
[InlineData("information")]
public void StringValuesConvertToEnumByName(string level)
{
var value = new StringArgumentValue(nameof(LogEventLevel.Information));
var value = new StringArgumentValue(level);

var actual = value.ConvertTo(typeof(LogEventLevel), new());

Expand Down

0 comments on commit 296a8ba

Please sign in to comment.