Class EntityCollection
A default implementation for IEntityCollection.
Implements
Inherited Members
Namespace: SpiceSharp.Entities
Assembly: SpiceSharp.dll
Syntax
public class EntityCollection : IEntityCollection, ICollection<IEntity>, IEnumerable<IEntity>, IEnumerable, ICloneable<IEntityCollection>
Constructors
EntityCollection()
Initializes a new instance of the EntityCollection class.
Declaration
public EntityCollection()
EntityCollection(IEqualityComparer<string>)
Initializes a new instance of the EntityCollection class.
Declaration
public EntityCollection(IEqualityComparer<string> comparer)
Parameters
Type | Name | Description |
---|---|---|
IEqualityComparer<string> | comparer | The comparer. |
Properties
Comparer
Gets the comparer used to compare Entity names.
Declaration
public IEqualityComparer<string> Comparer { get; }
Property Value
Type | Description |
---|---|
IEqualityComparer<string> | The comparer. |
Count
Gets the number of elements contained in the ICollection<T>.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
IsReadOnly
Gets a value indicating whether the ICollection<T> is read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
bool |
this[string]
Gets the IEntity with the specified name.
Declaration
public IEntity this[string name] { get; }
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the entity. |
Property Value
Type | Description |
---|---|
IEntity | The IEntity. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
KeyNotFoundException | Thrown if no entity with the name |
Keys
Gets the keys.
Declaration
public IEnumerable<string> Keys { get; }
Property Value
Type | Description |
---|---|
IEnumerable<string> | The keys. |
Methods
Add(IEntity)
Adds an item to the ICollection<T>.
Declaration
public void Add(IEntity item)
Parameters
Type | Name | Description |
---|---|---|
IEntity | item | The object to add to the ICollection<T>. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
ArgumentException | Thrown if another entity with the same name already exists. |
ByType<E>()
Gets all entities that are of a specified type.
Declaration
public IEnumerable<E> ByType<E>() where E : IEntity
Returns
Type | Description |
---|---|
IEnumerable<E> | The entities. |
Type Parameters
Name | Description |
---|---|
E | The type of entity. |
Clear()
Removes all items from the ICollection<T>.
Declaration
public void Clear()
Clone()
Clones the instance.
Declaration
public IEntityCollection Clone()
Returns
Type | Description |
---|---|
IEntityCollection | The cloned instance. |
Contains(IEntity)
Determines whether this instance contains the object.
Declaration
public bool Contains(IEntity entity)
Parameters
Type | Name | Description |
---|---|---|
IEntity | entity | The entity. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
Contains(string)
Determines whether this instance contains an IEntity with the specified name.
Declaration
public bool Contains(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name. |
Returns
Type | Description |
---|---|
bool |
|
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public virtual IEnumerator<IEntity> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<IEntity> | An enumerator that can be used to iterate through the collection. |
OnEntityAdded(EntityEventArgs)
Raises the EntityAdded event.
Declaration
protected virtual void OnEntityAdded(EntityEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
EntityEventArgs | args | The EntityEventArgs instance containing the event data. |
OnEntityRemoved(EntityEventArgs)
Raises the EntityRemoved event.
Declaration
protected virtual void OnEntityRemoved(EntityEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
EntityEventArgs | args | The EntityEventArgs instance containing the event data. |
Remove(IEntity)
Removes the first occurrence of a specific object from the ICollection<T>.
Declaration
public bool Remove(IEntity item)
Parameters
Type | Name | Description |
---|---|---|
IEntity | item | The object to remove from the ICollection<T>. |
Returns
Type | Description |
---|---|
bool | true if |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
Remove(string)
Removes the IEntity with specified name.
Declaration
public bool Remove(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the entity. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
TryGetEntity(string, out IEntity)
Tries to find an Entity in the collection.
Declaration
public bool TryGetEntity(string name, out IEntity entity)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the entity. |
IEntity | entity | The entity. |
Returns
Type | Description |
---|---|
bool |
|
Events
EntityAdded
Occurs when an entity has been added.
Declaration
public event EventHandler<EntityEventArgs> EntityAdded
Event Type
Type | Description |
---|---|
EventHandler<EntityEventArgs> |
EntityRemoved
Occurs when an entity has been removed.
Declaration
public event EventHandler<EntityEventArgs> EntityRemoved
Event Type
Type | Description |
---|---|
EventHandler<EntityEventArgs> |