using System;
using System.Collections.Generic;
namespace Nuclex.Support.Collections {
/// Base class for objects that can be parented to an owner
/// Type of the parent object
public class Parentable where ParentType : class {
/// Assigns a new parent to this instance
internal void SetParent(ParentType parent) {
ParentType oldParent = this.parent;
this.parent = parent;
OnParentChanged(oldParent);
}
/// The parent object that owns this instance
protected ParentType Parent {
get { return this.parent; }
}
/// Invoked whenever the instance's owner changes
///
/// 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.
///
/// Previous owner of the instance
protected virtual void OnParentChanged(ParentType oldParent) { }
/// Current parent of this object
private ParentType parent;
}
} // namespace Nuclex.Support.Collections