2d145ca867
git-svn-id: file:///srv/devel/repo-conversion/nusu@9 d2e56fa2-650e-0410-a79f-9358c0239efd
38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
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> {
|
|
|
|
/// <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
|