Skip to content

Commit

Permalink
fixes #111 - case-insensitive method argument-matching
Browse files Browse the repository at this point in the history
  • Loading branch information
MV10 committed Aug 29, 2018
1 parent a6177b7 commit 5cb8e92
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static void CallConfigurationMethods(ILookup<string, Dictionary<string, IConfigu
if (methodInfo != null)
{
var call = (from p in methodInfo.GetParameters().Skip(1)
let directive = method.Value.FirstOrDefault(s => s.Key == p.Name)
let directive = method.Value.FirstOrDefault(s => s.Key.Equals(p.Name, StringComparison.OrdinalIgnoreCase))
select directive.Key == null ? p.DefaultValue : directive.Value.ConvertTo(p.ParameterType, declaredLevelSwitches)).ToList();

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

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

Expand Down

0 comments on commit 5cb8e92

Please sign in to comment.