ce8df64be5
git-svn-id: file:///srv/devel/repo-conversion/nusu@1 d2e56fa2-650e-0410-a79f-9358c0239efd
39 lines
1.3 KiB
C#
39 lines
1.3 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>
|
|
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
|