Uh oh!
There was an error while loading. Please reload this page.
Add ConfigurationIgnoreAttribute - #126396
Conversation
Tagging subscribers to this area: @dotnet/area-extensions-configuration |
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]. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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);
}
Uh oh!
There was an error while loading. Please reload this page.
bf00b83 to
bac2378Compare
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.