Show / Hide Table of Contents

Class ParentAwareComponentBase

Simple (and optional) base class for components attached to a class implementing IObjectWithComponents. Adds useful events and some helper functions to allow performing type-checking of parent, or requiring that the object it's attached to has or does not have certain types of components.

Inheritance
object
ParentAwareComponentBase
ParentAwareComponentBase<TParent>
Implements
IParentAwareComponent
Inherited Members
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: GoRogue.Components.ParentAware
Assembly: GoRogue.dll
Syntax
public class ParentAwareComponentBase : IParentAwareComponent
Remarks

This class may be added as a component to any class that implements IObjectWithComponents, however components inheriting from this class will not implicitly fail in any way if it is used with a class that does not implement that interface. Certain functions such as IncompatibleWith<TComponent>(object?, EventArgs) do require that their parent implement IObjectWithComponents, and in general there is no guarantee that the Parent field gets updated if the parent doesn't implement that interface; however you can sync the parent field manually as applicable.

In most cases, the intended usage is to add this as a component to a class that implements IObjectWithComponents; however the option of not doing so and manually syncing the Parent field instead allows this functionality to be tied into other component systems as well.

Constructors

View Source

ParentAwareComponentBase()

Declaration
public ParentAwareComponentBase()

Properties

View Source

Parent

The object the component is attached to.

Declaration
public virtual object? Parent { get; set; }
Property Value
Type Description
object

Methods

View Source

IncompatibleWith<TComponent>(object?, EventArgs)

Add as a handler to Added to enforce that this component may not be added to an object that has a component of type TComponent. May also be used to enforce that the component can't have multiple instances of itself attached to the same object by using Added += IncompatibleWith<MyOwnType>.

Declaration
public void IncompatibleWith<TComponent>(object? s, EventArgs e) where TComponent : class
Parameters
Type Name Description
object s
EventArgs e
Type Parameters
Name Description
TComponent

Type of the component this one is incompatible with.

Remarks

This function only works if the parent is of type IObjectWithComponents. If the parent is not of that type, this function will throw an exception.

View Source

ParentTypeCheck<TParent>(object?, EventArgs)

Add as a handler to Added to enforce that this component must be parented to an object that inherits from/implements TParent.

Declaration
public static void ParentTypeCheck<TParent>(object? s, EventArgs e)
Parameters
Type Name Description
object s
EventArgs e
Type Parameters
Name Description
TParent

Type of object that must be this component's parent.

Events

View Source

Added

Fires when the component is attached to an object.

Declaration
public event EventHandler? Added
Event Type
Type Description
EventHandler
View Source

Removed

Fires when the component is unattached from an object

Declaration
public event EventHandler<ParentAwareComponentRemovedEventArgs<object>>? Removed
Event Type
Type Description
EventHandler<ParentAwareComponentRemovedEventArgs<object>>

Implements

IParentAwareComponent

Extension Methods

Utility.Yield<T>(T)
  • View Source
In this article
Back to top Generated by DocFX