Skip to content

Add ConfigurationIgnoreAttribute#126396

Open
rosebyte wants to merge 7 commits intodotnet:mainfrom
rosebyte:feature/configuration-ignore-attribute
Open

Add ConfigurationIgnoreAttribute#126396
rosebyte wants to merge 7 commits intodotnet:mainfrom
rosebyte:feature/configuration-ignore-attribute

Conversation

@rosebyte
Copy link
Copy Markdown
Member

@rosebyte rosebyte commented Apr 1, 2026

Fixes #125111

Add ConfigurationIgnoreAttribute so configuration binding can explicitly skip selected properties.

Changes

  • Added ConfigurationIgnoreAttribute to Microsoft.Extensions.Configuration.Abstractions (implementation + ref).
  • Reflection binder now skips ignored properties.
  • Constructor-parameter/property matching now treats ignored properties as non-bindable.
  • Source generator updated to parse and honor ignored properties.
  • Added tests for ignore behavior, ErrorOnUnknownConfiguration, and constructor matching with ignored properties.
  • Updated Abstractions README/PACKAGE examples.

Validation

  • dotnet build for Abstractions and Binder.
  • Binder unit tests: 296 passed, 0 failed.
  • Source-generation tests: 347 total, 0 failed (28 skipped by conditions).

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ConfigurationIgnoreAttribute in Microsoft.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].

@cincuranet cincuranet changed the title Add COnfigurationIgnoreAttribute Add ConfigurationIgnoreAttribute Apr 2, 2026
Copilot AI review requested due to automatic review settings April 9, 2026 11:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
                }

@rosebyte rosebyte force-pushed the feature/configuration-ignore-attribute branch from bf00b83 to bac2378 Compare April 9, 2026 13:24
Copilot AI review requested due to automatic review settings April 9, 2026 13:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings April 9, 2026 16:50
@rosebyte rosebyte marked this pull request as ready for review April 9, 2026 16:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add ConfigurationIgnoreAttribute to exclude properties from configuration binding

4 participants