Class ComponentList<TEntity>
- Namespace
- MonkeyLoader.Components
- Assembly
- MonkeyLoader.dll
Implements a component list for entities.
public sealed class ComponentList<TEntity> : IComponentList<TEntity> where TEntity : class, IEntity<TEntity>
Type Parameters
TEntity
The type of the entity.
- Inheritance
-
ComponentList<TEntity>
- Implements
-
IComponentList<TEntity>
- Inherited Members
Constructors
ComponentList(TEntity)
Creates a component list for the given entity.
public ComponentList(TEntity entity)
Parameters
entity
TEntityThe entity that this component list is for.
Properties
Entity
Gets the entity that this component list is for.
public TEntity Entity { get; }
Property Value
- TEntity
Methods
Add(IComponent<TEntity>)
Adds a component to this Entity's component list.
public void Add(IComponent<TEntity> component)
Parameters
component
IComponent<TEntity>The component to add.
GetAll<TComponent>()
Gets a sequence of all components assignable to TComponent
, in order of insertion.
public IEnumerable<TComponent> GetAll<TComponent>() where TComponent : class, IComponent<TEntity>
Returns
- IEnumerable<TComponent>
A sequence of all matching components in order of insertion.
Type Parameters
TComponent
The type of the component(s). Should be an interface.
GetAll<TComponent>(Predicate<TComponent>)
Gets a sequence of all components assignable to TComponent
, in order of insertion.
public IEnumerable<TComponent> GetAll<TComponent>(Predicate<TComponent> predicate) where TComponent : class, IComponent<TEntity>
Parameters
predicate
Predicate<TComponent>A function to test each component for a condition.
Returns
- IEnumerable<TComponent>
A sequence of all matching components in order of insertion that satisfy the
predicate
.
Type Parameters
TComponent
The type of the component(s). Should be an interface.
Get<TComponent>()
Gets the first component (in order of insertion) assignable to TComponent
.
public TComponent Get<TComponent>() where TComponent : class, IComponent<TEntity>
Returns
- TComponent
The found
TComponent
.
Type Parameters
TComponent
The type of the component. Should be an interface.
Exceptions
- ComponentNotFoundException
When there is no
TComponent
.
Get<TComponent>(Predicate<TComponent>)
Gets the first component (in order of insertion) assignable to TComponent
.
public TComponent Get<TComponent>(Predicate<TComponent> predicate) where TComponent : class, IComponent<TEntity>
Parameters
predicate
Predicate<TComponent>A function to test each component for a condition.
Returns
- TComponent
The found
TComponent
.
Type Parameters
TComponent
The type of the component. Should be an interface.
Exceptions
- ComponentNotFoundException
When there is no
TComponent
that satisfies thepredicate
.
TryGet<TComponent>(Predicate<TComponent>, out TComponent?)
Tries to get the first component (in order of insertion) assignable to
TComponent
that satisfied the predicate
.
public bool TryGet<TComponent>(Predicate<TComponent> predicate, out TComponent? component) where TComponent : class, IComponent<TEntity>
Parameters
predicate
Predicate<TComponent>A function to test each component for a condition.
component
TComponentThe component if one was found; otherwise,
default(
.TComponent
)
Returns
- bool
true
if aTComponent
satisfying thepredicate
was found; otherwise,false
.
Type Parameters
TComponent
The type of the component. Should be an interface.
TryGet<TComponent>(out TComponent?)
Tries to get the first component (in order of insertion) assignable to TComponent
.
public bool TryGet<TComponent>(out TComponent? component) where TComponent : class, IComponent<TEntity>
Parameters
component
TComponentThe component if one was found; otherwise,
default(
.TComponent
)
Returns
- bool
true
if aTComponent
was found; otherwise,false
.
Type Parameters
TComponent
The type of the component. Should be an interface.