Skip to content

Commit 5cb8e92

Browse files
committed
fixes #111 - case-insensitive method argument-matching
1 parent a6177b7 commit 5cb8e92

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static void CallConfigurationMethods(ILookup<string, Dictionary<string, IConfigu
327327
if (methodInfo != null)
328328
{
329329
var call = (from p in methodInfo.GetParameters().Skip(1)
330-
let directive = method.Value.FirstOrDefault(s => s.Key == p.Name)
330+
let directive = method.Value.FirstOrDefault(s => s.Key.Equals(p.Name, StringComparison.OrdinalIgnoreCase))
331331
select directive.Key == null ? p.DefaultValue : directive.Value.ConvertTo(p.ParameterType, declaredLevelSwitches)).ToList();
332332

333333
var parm = methodInfo.GetParameters().FirstOrDefault(i => i.ParameterType == typeof(IConfiguration));
@@ -342,10 +342,15 @@ static void CallConfigurationMethods(ILookup<string, Dictionary<string, IConfigu
342342

343343
internal static MethodInfo SelectConfigurationMethod(IEnumerable<MethodInfo> candidateMethods, string name, Dictionary<string, IConfigurationArgumentValue> suppliedArgumentValues)
344344
{
345+
// Per issue #111, it is safe to use case-insensitive matching on argument names. The CLR doesn't permit this type
346+
// of overloading, and the Microsoft.Extensions.Configuration keys are case-insensitive (case is preserved with some
347+
// config sources, but key-matching is case-insensitive and case-preservation does not appear to be guaranteed).
345348
return candidateMethods
346349
.Where(m => m.Name == name &&
347-
m.GetParameters().Skip(1).All(p => p.HasDefaultValue || suppliedArgumentValues.Any(s => s.Key == p.Name)))
348-
.OrderByDescending(m => m.GetParameters().Count(p => suppliedArgumentValues.Any(s => s.Key == p.Name)))
350+
m.GetParameters().Skip(1)
351+
.All(p => p.HasDefaultValue || suppliedArgumentValues.Any(s => s.Key.Equals(p.Name, StringComparison.OrdinalIgnoreCase))))
352+
.OrderByDescending(m =>
353+
m.GetParameters().Count(p => suppliedArgumentValues.Any(s => s.Key.Equals(p.Name, StringComparison.OrdinalIgnoreCase))))
349354
.FirstOrDefault();
350355
}
351356

0 commit comments

Comments
 (0)