-
Notifications
You must be signed in to change notification settings - Fork 982
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
Fix nullability bug in BindingContext #2646
Conversation
src/System.Windows.Forms/src/System/Windows/Forms/BindingContext.cs
Outdated
Show resolved
Hide resolved
|
Hmm this would definitely break void ICollection.CopyTo(Array ar, int index)
{
ScrubWeakRefs();
_listManagers.CopyTo(ar, index);
} |
Yes, if you don't want to take that breaking change you could rewrap the KVPs though. I don't think that method call is common since its hidden behind an explicit interface implementation, callers would have to cast to use it. This is probably also something to discuss in context of #2644 when implementing generic collection types, because it will determine whether we use |
Perhaps the more common case would be the following, that would throw an var context = new BindingContext();
// Add items...
foreach (DictionaryEntry in context)
{
} |
You are right of course. Lets not discuss changing implementation here, this belongs more into the discussion of #2644, its just a warning when doing nullability but for #2644 its a major decision what type you take as collection content (with the option to separate the decision out into its own issue). Thanks for bringing it up though! |
Also I think this warning is a false-positive, non-generic dictionaries won't return a null DictionaryEntry. Its probably not possible to express this with annotations though so you get a warning anyways. |
I tried suppressing it with |
src/System.Windows.Forms/src/System/Windows/Forms/BindingContext.cs
Outdated
Show resolved
Hide resolved
Updated just to fix the nullability bug of |
Codecov Report
@@ Coverage Diff @@
## master #2646 +/- ##
==================================================
+ Coverage 57.5673% 58.11907% +0.55177%
==================================================
Files 1233 1240 +7
Lines 417560 423004 +5444
Branches 38754 38852 +98
==================================================
+ Hits 240378 245846 +5468
+ Misses 171808 171784 -24
Partials 5374 5374
|
@RussKie how does this bug fix look? |
Thank you all |
Proposed Changes
ICollection.SyncRoot
return non-null valueTODOWe have the following warningsHappens in cases like below in
foreach (DictionaryEntry de in _listManagers)
, how are we unboxing a possibly null value/cc @weltkante
Microsoft Reviewers: Open in CodeFlow