Skip to content

Commit

Permalink
Merge pull request #155 from mashbrno/dev
Browse files Browse the repository at this point in the history
Exceptions when misconfigured
  • Loading branch information
nblumhardt authored Jun 2, 2019
2 parents 0e42736 + 82199f0 commit ad2f33e
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ internal static MethodInfo SelectConfigurationMethod(IEnumerable<MethodInfo> can
// 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
var selectedMethod = candidateMethods
.Where(m => m.Name == name)
.Where(m => m.GetParameters()
.Skip(1)
Expand All @@ -366,6 +366,27 @@ internal static MethodInfo SelectConfigurationMethod(IEnumerable<MethodInfo> can
matchingArgs.Count(p => p.ParameterType == typeof(string)));
})
.FirstOrDefault();

if (selectedMethod == null)
{
var methodsByName = candidateMethods
.Where(m => m.Name == name)
.Select(m => $"{m.Name}({string.Join(", ", m.GetParameters().Skip(1).Select(p => p.Name))})")
.ToList();

if (!methodsByName.Any())
SelfLog.WriteLine($"Unable to find a method called {name}. Candidate methods are:{Environment.NewLine}{string.Join(Environment.NewLine, candidateMethods)}");
else
SelfLog.WriteLine($"Unable to find a method called {name} "
+ (suppliedArgumentNames.Any()
? "for supplied arguments: " + string.Join(", ", suppliedArgumentNames)
: "with no supplied arguments")
+ ". Candidate methods are:"
+ Environment.NewLine
+ string.Join(Environment.NewLine, methodsByName));
}

return selectedMethod;
}

static bool ParameterNameMatches(string actualParameterName, string suppliedName)
Expand Down

0 comments on commit ad2f33e

Please sign in to comment.