2007-02-28 20:20:50 +00:00
|
|
|
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>
|
2007-04-02 18:48:28 +00:00
|
|
|
public class Parentable<ParentType> where ParentType : class {
|
2007-02-28 20:20:50 +00:00
|
|
|
|
|
|
|
/// <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
|