Provided a common class for observable collections similar to what the .NET Framework 3.0 offers; ParentingCollection no longer requires the parent type to be a reference type; Laid the foundation for a new progress tracking framework that can be used to drive progress bars, loading screens and such

git-svn-id: file:///srv/devel/repo-conversion/nusu@9 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2007-04-16 17:18:16 +00:00
parent 355e5766d4
commit 2d145ca867
11 changed files with 379 additions and 6 deletions

View file

@ -15,8 +15,7 @@ namespace Nuclex.Support.Collections {
/// <typeparam name="ParentType">Type of the parent object to assign to items</typeparam>
/// <typeparam name="ItemType">Type of the items being managed in the collection</typeparam>
public class ParentingCollection<ParentType, ItemType> : Collection<ItemType>
where ItemType : Parentable<ParentType>
where ParentType : class {
where ItemType : Parentable<ParentType> {
/// <summary>Reparents all elements in the collection</summary>
/// <param name="parent">New parent to take ownership of the items</param>
@ -30,7 +29,7 @@ namespace Nuclex.Support.Collections {
/// <summary>Clears all elements from the collection</summary>
protected override void ClearItems() {
for(int index = 0; index < Count; ++index)
base[index].SetParent(null);
base[index].SetParent(default(ParentType));
base.ClearItems();
}
@ -46,7 +45,7 @@ namespace Nuclex.Support.Collections {
/// <summary>Removes an element from the collection</summary>
/// <param name="index">Index of the element to remove</param>
protected override void RemoveItem(int index) {
base[index].SetParent(null);
base[index].SetParent(default(ParentType));
base.RemoveItem(index);
}
@ -70,7 +69,7 @@ namespace Nuclex.Support.Collections {
if(disposeItems) {
// Have the items do their cleanup work
Reparent(null);
Reparent(default(ParentType));
// Dispose of all the items in the collection that implement IDisposable
foreach(ItemType item in this) {