Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small ConfigurationBinder Cleanup #79042

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -361,24 +361,26 @@ private static void BindInstance(
}
}

Debug.Assert(bindingPoint.Value is not null);

// At this point we know that we have a non-null bindingPoint.Value, we just have to populate the items
// using the IDictionary<> or ICollection<> interfaces, or properties using reflection.
Type? dictionaryInterface = FindOpenGenericInterface(typeof(IDictionary<,>), type);

if (dictionaryInterface != null)
{
BindDictionary(bindingPoint.Value!, dictionaryInterface, config, options);
BindDictionary(bindingPoint.Value, dictionaryInterface, config, options);
}
else
{
Type? collectionInterface = FindOpenGenericInterface(typeof(ICollection<>), type);
if (collectionInterface != null)
{
BindCollection(bindingPoint.Value!, collectionInterface, config, options);
BindCollection(bindingPoint.Value, collectionInterface, config, options);
}
else
{
BindProperties(bindingPoint.Value!, config, options);
BindProperties(bindingPoint.Value, config, options);
}
}
}
Expand Down Expand Up @@ -590,17 +592,8 @@ private static void BindDictionary(
return;
}

Debug.Assert(dictionary is not null);


MethodInfo tryGetValue = dictionaryType.GetMethod("TryGetValue", DeclaredOnlyLookup)!;
PropertyInfo? indexerProperty = dictionaryType.GetProperty("Item", DeclaredOnlyLookup);

if (indexerProperty is null || !indexerProperty.CanWrite)
{
// Cannot set any item on the dictionary object.
return;
}
PropertyInfo indexerProperty = dictionaryType.GetProperty("Item", DeclaredOnlyLookup)!;

foreach (IConfigurationSection child in config.GetChildren())
{
Expand Down