Imported newly created Nuclex.Support library which contains various supporting classes not related to a specific topic
git-svn-id: file:///srv/devel/repo-conversion/nusu@1 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
commit
ce8df64be5
10 changed files with 1043 additions and 0 deletions
38
Source/Collections/Parentable.cs
Normal file
38
Source/Collections/Parentable.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
/// <summary>Base class for objects that can be parented to an owner</summary>
|
||||
/// <typeparam name="ParentType">Type of the parent object</typeparam>
|
||||
public class Parentable<ParentType>
|
||||
where ParentType : class {
|
||||
|
||||
/// <summary>Assigns a new parent to this instance</summary>
|
||||
internal void SetParent(ParentType parent) {
|
||||
ParentType oldParent = this.parent;
|
||||
this.parent = parent;
|
||||
|
||||
OnParentChanged(oldParent);
|
||||
}
|
||||
|
||||
/// <summary>The parent object that owns this instance</summary>
|
||||
protected ParentType Parent {
|
||||
get { return this.parent; }
|
||||
}
|
||||
|
||||
/// <summary>Invoked whenever the instance's owner changes</summary>
|
||||
/// <remarks>
|
||||
/// When items are parented for the first time, the oldParent argument will
|
||||
/// be null. Also, if the element is removed from the collection, the
|
||||
/// current parent will be null.
|
||||
/// </remarks>
|
||||
/// <param name="oldParent">Previous owner of the instance</param>
|
||||
protected virtual void OnParentChanged(ParentType oldParent) { }
|
||||
|
||||
/// <summary>Current parent of this object</summary>
|
||||
private ParentType parent;
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Support.Collections
|
||||
Loading…
Add table
Add a link
Reference in a new issue