Blish-HUD
Blish-HUD copied to clipboard
Control collection parent fixes
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
- Cancelling an
AddChild
orRemoveChild
action from a Container should no longer cause theParent
property of the control in question to be in a potentially invalid state. - Create a copy of the internal array when iterating, as with some BCL concurrent types, as we can't be sure external code will dispose of the enumerator correctly.
- Provide (internal) ReaderWriterLockSlim helper methods that allow basic read and write locks to use
using (...) { ... }
syntax rather than having to use try/finally everywhere. - No longer clear
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. - Update Container to explicitly set .Parent property on added or removed children.
Notes:
- I'm working on the assumption that the intended behaviour for the control collection is that it never contains nulls and never has duplicates, if either of those assumptions are incorrect then I'll need to rework this change.
- I'm unsure if the indexer setter for
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.