-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Prefer most derived member in Configuration Binder source generator #101316
Conversation
Tagging subscribers to this area: @dotnet/area-extensions-configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
...libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the quick fix here!
Do you think this could be backported to 8.0.x?
...raries/Microsoft.Extensions.Configuration.Binder/gen/ConfigurationBindingGenerator.Parser.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per #101316 (review) I suspect that this might be introducing a slight regression.
Given that this is a likely candidate for backporting, it might make sense to investigate further.
I'll add a test case for an override that only overrides the Getter. We did have a test for the case where a |
Seems we still have a failure of the Reflection binder:
@eerhardt -- does that sound right? That seems to indicate that #101273 might be broken even without the source generator. |
Interesting: the reflection binder has a different heuristic. runtime/src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs Lines 987 to 1004 in c1f9161
It never does any resolution by name, but builds a list in order from derived to base. So it will set both the hidden and non-hidden members through reflection, using the same configuration data. That's unusual behavior - but we could replicate it if we casted the LHS in the source generator to the base type. |
@ericstj I think we need to keep the runtime behavior for consistency. Even if it looks unusual behavior but seems not many people complained about it. |
See my comment on #101273 (comment). For the case I hit the issue, the base enum is a superset of the derived enum. The derived class is trying to limit which values can be set. |
Do we want to? Are there tests validating this behavior? |
I'm not planning to change the reflection binder's behavior in this PR. Nor am I planning to change the source generator to bind many different propreties like the reflection binder does. I'm inclined to more closely match the reflection-binder's selection algorithm for finding the most-derived property. I think that will be the minimal change while unblocking @eerhardt. I'm running some tests and will make a new change to this PR shortly. |
Failures are known issues and don't block build or testing. |
/backport to release/8.0-staging |
Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/8881506956 |
…otnet#101316) * Prefer most derived member in Configuration Binder source generator * Skip overridden properties in config source generator - include only definitions
…otnet#101316) * Prefer most derived member in Configuration Binder source generator * Skip overridden properties in config source generator - include only definitions
…otnet#101316) * Prefer most derived member in Configuration Binder source generator * Skip overridden properties in config source generator - include only definitions
Fix #101267 #101273
CC @eerhardt