Uh oh!
There was an error while loading. Please reload this page.
ConfigurationBinder handles ISet<> - #68133
Conversation
ghost
commented
Apr 17, 2022
Tagging subscribers to this area: @dotnet/area-extensions-configuration |
Uh oh!
There was an error while loading. Please reload this page.
tarekgh
commented
Apr 18, 2022
@SteveDunn could you please resolve the file conflicts? |
a332a69 to
133ee2eCompareUh oh!
There was an error while loading. Please reload this page.
SteveDunn
commented
Apr 19, 2022
Rebased from main and resolved conflicts. |
tarekgh
left a comment
There was a problem hiding this comment.
LGTM. Thanks @SteveDunn
@maryamariyan do you want to have a quick look?
halter73
commented
Apr 21, 2022
The It might end up that we test for I would like a fix to publicinterfaceICustomCollection<outT>:IEnumerable<T>{}publicclassMyClassWithCustomCollection{publicICustomCollection<string>CustomCollection{get;set;}}[Fact]publicvoidSkipsCustomCollection(){varconfigurationBuilder=newConfigurationBuilder();configurationBuilder.AddInMemoryCollection(newDictionary<string,string>{["CustomCollection:0"]="Yo!",});varconfig=configurationBuilder.Build();varinstance=config.Get<MyClassWithCustomCollection>()!;Assert.Null(instance.CustomCollection);} |
SteveDunn
commented
Apr 29, 2022
Thanks for the suggestion @halter73 . I've fixed the issues mentioned, and the example test case you provided is now included. I also added similar cases for custom dictionaries. |
halter73
left a comment
There was a problem hiding this comment.
Upon further review I think we should throw for custom interfaces implementing known collection interface, it just shouldn't be an ArgumentException thrown when trying to set a property value, it should be an InvalidOperationException thrown while trying to activate the type like we do for other interfaces.
In my last comment I link to a diff to your PR that has the behavior I want as far as that goes. I didn't go ahead and make all the changes I suggested. For example, we still need to limit sets to strings and enums and write tests for that, but please feel free to cherry-pick these changes.
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.
I added the above test and got it passing, but there was no way for this to remain green whilst all others remained green. Do we want to change this behaviour from throwing this exception to just skipping the custom collections (enumerables, sets, dictionaries)? |
This is one of a few of my PRs laying dormant. Is there anything I need to do to progress them? |
halter73
commented
May 21, 2022
No. It's better to stay consistent and throw from all custom collections. That's why I changed all the |
halter73
left a comment
There was a problem hiding this comment.
Sorry for the slow turnaround getting back to this. It looks really good. Thanks for sticking with this so long!
I still do want to add a test for a collection without a public Add method since we nearly regressed this. I asked for this, but it was tucked away in a longer comment.
We should add a test that binds to an explicitly implemented
ICollection<string>to verify we don't regress this in the future.
eerhardt
commented
May 24, 2022
@SteveDunn - I think this is the last feedback to address on this PR, and then it can be merged. |
eerhardt
left a comment
There was a problem hiding this comment.
I guess I had 2 more comments.
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.
da7ee3f to
4f66fdaCompareSteveDunn
commented
Jun 12, 2022
I think everything has now been addressed for this. And I also just rebased. |
There was a problem hiding this comment.
I don't think this fits in with the name of the method: IsArrayCompatibleReadOnlyInterface - ICollection<> is not "read-only".
Also, later in the BindInstance method we are checking for ICollection<>, does it need to be in both places?
There was a problem hiding this comment.
I think the method is answering the question 'Should the type be treated as immutable?" - e.g. if it's one of these types, then return true to say not to append to the source, but clone it to a new collection.
I've renamed it as such, although I do think it could be clearer. Do you have any thoughts?
There was a problem hiding this comment.
Why do we need to check for ICollection<> in both places?
There was a problem hiding this comment.
I think the second check for ICollection<> is looking for an Add method to determine whether to set (add) members of the collection, or whether to bind to properties (line 358).
Do you have any thoughts on how this could be made clearer? To be perfectly honest, I do find this method rather confusing!
Uh oh!
There was an error while loading. Please reload this page.
9252089 to
ca1defeCompareSteveDunn
commented
Jul 18, 2022
No worries at all, you must be busy (if you need an additional member of the team, I'd love to join!) |
tarekgh
commented
Jul 19, 2022
The failure in Windows x64 Debug run is unrelated and tracked by #72428 |
Fixes#66141