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
TEntityThe 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
entityTEntityThe 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
componentIComponent<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
TComponentThe 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
predicatePredicate<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
TComponentThe 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
TComponentThe 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
predicatePredicate<TComponent>A function to test each component for a condition.
Returns
- TComponent
The found
TComponent.
Type Parameters
TComponentThe type of the component. Should be an interface.
Exceptions
- ComponentNotFoundException
When there is no
TComponentthat 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
predicatePredicate<TComponent>A function to test each component for a condition.
componentTComponentThe component if one was found; otherwise,
default(.TComponent)
Returns
- bool
trueif aTComponentsatisfying thepredicatewas found; otherwise,false.
Type Parameters
TComponentThe 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
componentTComponentThe component if one was found; otherwise,
default(.TComponent)
Returns
- bool
trueif aTComponentwas found; otherwise,false.
Type Parameters
TComponentThe type of the component. Should be an interface.