Skip to content

Commit

Permalink
Make property set logic robust to irregular properties
Browse files Browse the repository at this point in the history
  • Loading branch information
nblumhardt committed Aug 3, 2024
1 parent 04d694d commit df8c383
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,14 @@ bool TryCallCtor(Type type, Dictionary<string, IConfigurationSection> suppliedAr
}
else
{
return new { ci, args, isCallable = false, matches, stringMatches, suppliedNames };
return new { ci, args, isCallable = false, matches, stringMatches,
usedArguments = suppliedNames };
}
}
}
return new { ci, args, isCallable = true, matches, stringMatches, suppliedNames };
return new { ci, args, isCallable = true, matches, stringMatches,
usedArguments = suppliedNames };
})
.Where(binding => binding.isCallable)
.OrderByDescending(binding => binding.matches)
Expand All @@ -217,7 +219,11 @@ bool TryCallCtor(Type type, Dictionary<string, IConfigurationSection> suppliedAr

foreach (var pi in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
if (!binding.suppliedNames.Contains(pi.Name) && suppliedArguments.TryGetValue(pi.Name, out var section) && pi.CanWrite)
if (!binding.usedArguments.Contains(pi.Name) &&
suppliedArguments.TryGetValue(pi.Name, out var section)
&& pi.CanWrite &&
// This avoids trying to call esoteric indexers and so on.
pi.GetSetMethod(false)?.GetParameters().Length == 1)
{
var propertyValue = FromSection(section, _configurationAssemblies);
try
Expand Down

0 comments on commit df8c383

Please sign in to comment.