Open eksime opened 1 year ago
Gonna do some testing with this build to make sure there are no weird behaviors, but appears to look good and assumptions appear to all be correct.
Kudos, SonarCloud Quality Gate passed!
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
thinking about it, would it be better to throw ArgumentNullException on operations that involve trying to insert or remove null values?
thinking about it, would it be better to throw ArgumentNullException on operations that involve trying to insert or remove null values?
Sorry for the delays on this. Yes, I think you're right. I can't think of a scenario where it would be intended and the short-circuit might mask a module or core bug. Though, like with lists, it may be safe to keep it off of the remove function. Open to your thoughts, though.
The only item that I think we might need to change is:
No longer clear Parent on controls when calling Clear - this should be handled by the Container as there's no guarantee that the ControlCollection is being used for parenting/hierarchy purposes.
This is correct, but it's a breaking change that I can't guarantee won't cause problems within one of the modules. Throwing an exception on inserting/removing null values would also be a breaking change, but seems less likely, and I imagine we would catch it during preview testing.
Open to your thoughts on that as well.
Discord Discussion
Breaking change: no
Likely fixes #886
This reworks the internals of the
ControlCollection<T>
class, with the following changes:null
values are unable to be added to the collection, with short-circuits for methods whenitem
isnull
AddChild
orRemoveChild
action from a Container should no longer cause theParent
property of the control in question to be in a potentially invalid state.using (...) { ... }
syntax rather than having to use try/finally everywhere.Parent
on controls when callingClear
- this should be handled by the Container as there's no guarantee that the ControlCollection is being used for parenting/hierarchy purposes.Notes:
ControlCollection<T>
should remove the item when attempting to set an indexed position tonull
or if it should be a noop, currently it removes the item. Additionally, if an index is set to an item that exists elsewhere in the collection, it currently overwrites the index, then removes the duplicate.