Skip to content

Commit 296a8ba

Browse files
authored
Merge pull request #432 from 0xced/string-to-enum-ignore-case
Make string to enum conversion case insensitive
2 parents e42be6a + 47f447a commit 296a8ba

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public StringArgumentValue(string providedValue)
5151
}
5252

5353
if (toTypeInfo.IsEnum)
54-
return Enum.Parse(toType, argumentValue);
54+
return Enum.Parse(toType, argumentValue, ignoreCase: true);
5555

5656
var convertor = ExtendedTypeConversions
5757
.Where(t => t.Key.GetTypeInfo().IsAssignableFrom(toTypeInfo))

test/Serilog.Settings.Configuration.Tests/StringArgumentValueTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,12 @@ public void ReferencingUndeclaredLevelSwitchThrows()
222222
Assert.Contains("\"LevelSwitches\":{\"$mySwitch\":", ex.Message);
223223
}
224224

225-
[Fact]
226-
public void StringValuesConvertToEnumByName()
225+
[Theory]
226+
[InlineData("Information")]
227+
[InlineData("information")]
228+
public void StringValuesConvertToEnumByName(string level)
227229
{
228-
var value = new StringArgumentValue(nameof(LogEventLevel.Information));
230+
var value = new StringArgumentValue(level);
229231

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

0 commit comments

Comments
 (0)