Open
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-extensions-configuration |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new ConfigurationIgnoreAttribute to the configuration abstractions and updates both the reflection-based binder and the source generator so selected properties can be explicitly excluded from binding.
Changes:
- Introduces
ConfigurationIgnoreAttributeinMicrosoft.Extensions.Configuration.Abstractions(impl + ref surface). - Updates reflection binder and source generator to skip ignored properties during binding and constructor-parameter matching.
- Adds/extends tests and updates package documentation examples to cover ignore behavior and
ErrorOnUnknownConfiguration.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.TestClasses.cs | Adds a primary-ctor test type with an ignored property to validate ctor/property matching behavior. |
| src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.Helpers.cs | Extends ComplexOptions with an ignored property for binder test coverage. |
| src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs | Adds tests asserting ignored properties aren’t bound and don’t trip ErrorOnUnknownConfiguration, plus ctor-matching behavior. |
| src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs | Skips ignored properties in reflection binding and in ctor-parameter/property equivalence checks; adds IsIgnoredProperty. |
| src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Specs/TypeIndex.cs | Ensures generator considers property.IsIgnored when deciding if a property is bindable. |
| src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Specs/Members/PropertySpec.cs | Adds IsIgnored flag to property spec model used by the generator. |
| src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Parser/KnownTypeSymbols.cs | Adds symbol lookup for ConfigurationIgnoreAttribute for generator parsing. |
| src/libraries/Microsoft.Extensions.Configuration.Binder/gen/ConfigurationBindingGenerator.Parser.cs | Parses [ConfigurationIgnore] and attempts to incorporate it into property/ctor matching. |
| src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/PACKAGE.md | Updates package example to mention/use [ConfigurationIgnore]. |
| src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/ConfigurationIgnoreAttribute.cs | Adds the new public attribute type. |
| src/libraries/Microsoft.Extensions.Configuration.Abstractions/ref/Microsoft.Extensions.Configuration.Abstractions.cs | Adds the attribute to the reference assembly surface area. |
| src/libraries/Microsoft.Extensions.Configuration.Abstractions/README.md | Updates README example to mention/use [ConfigurationIgnore]. |
src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/PACKAGE.md
Show resolved
Hide resolved
...raries/Microsoft.Extensions.Configuration.Binder/gen/ConfigurationBindingGenerator.Parser.cs
Show resolved
Hide resolved
...libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs
Show resolved
Hide resolved
...libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs
Show resolved
Hide resolved
This was referenced Apr 1, 2026
Open
tarekgh
reviewed
Apr 1, 2026
src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
Outdated
Show resolved
Hide resolved
tarekgh
reviewed
Apr 1, 2026
src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Specs/TypeIndex.cs
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs:256
- The constructor-parameter/property check is case-sensitive (p.Name == property.Name), but constructor parameter ↔ property equivalence is treated case-insensitively elsewhere (e.g., DoAllParametersHaveEquivalentProperties uses OrdinalIgnoreCase). This can cause properties whose names differ only by casing (common with primary ctors like "color" → "Color") to be bound again instead of going through the ctor-parameter path. Consider using an OrdinalIgnoreCase comparison here for consistency and to avoid unintended extra binding/setter side-effects.
if (constructorParameters is null || !constructorParameters.Any(p => p.Name == property.Name))
{
BindProperty(property, instance, configuration, options);
}
added 2 commits
April 9, 2026 15:24
bf00b83 to
bac2378
Compare
This was referenced Apr 9, 2026
cincuranet
approved these changes
Apr 10, 2026
Open
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #125111
Add
ConfigurationIgnoreAttributeso configuration binding can explicitly skip selected properties.Changes
ConfigurationIgnoreAttributetoMicrosoft.Extensions.Configuration.Abstractions(implementation + ref).ErrorOnUnknownConfiguration, and constructor matching with ignored properties.Validation
dotnet buildfor Abstractions and Binder.