Ctrl+K

EntityCollection

Declaration

public class Strawberry.Core.EntityCollection

Represents a strongly-typed collection of Entity objects, accessible by their string keys. Wraps a dictionary and implements both mutable and read-only dictionary interfaces.

Implements: System.Collections.Generic.IDictionary, System.Collections.Generic.IReadOnlyDictionary

Constructors

EntityCollection

Initializes a new instance of the EntityCollection class.

void EntityCollection()

Properties

this[]

Gets or sets the Entity with the specified key. Returns null if the key is not found when getting.

Entity this[string key] { get set }

Count

Gets the number of entities contained in the collection.

int Count { get }

IsReadOnly

Gets a value indicating whether the IDictionary object is read-only.

bool IsReadOnly { get }

Values

Gets a list containing all the entities in the collection. Note: This creates a new list allocation each time it is accessed.

IList<Entity> Values { get }

Keys

Gets a list containing all the keys in the collection. Note: This creates a new list allocation each time it is accessed.

IList<string> Keys { get }

Methods

Add

Adds an entity with the specified key to the collection. The changes to the collection will not apply until Flush is called.

void Add(string key, Entity value)

Parameters:

Name Type Description
key System.String The key of the entity to add.
value Strawberry.Core.Entity The entity to add.

Clear

Removes all entities from the collection.

void Clear()

ContainsKey

Determines whether the collection contains an entity with the specified key.

bool ContainsKey(string key)

Parameters:

Name Type Description
key System.String The key to locate in the collection.

Returns: true if the collection contains an entity with the key; otherwise, false.

Remove

Removes the entity with the specified key from the collection. The changes to the collection will not apply until Flush is called.

bool Remove(string key)

Parameters:

Name Type Description
key System.String The key of the entity to remove.

Returns: true if the entity is successfully removed; otherwise, false.

ImmediateRemove

bool ImmediateRemove(string key)

Parameters:

Name Type Description
key System.String

TryGetValue

Gets the entity associated with the specified key.

bool TryGetValue(string key, out Entity value)

Parameters:

Name Type Description
key System.String The key of the entity to get.
value out Strawberry.Core.Entity When this method returns, contains the entity associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter.

Returns: true if the collection contains an entity with the specified key; otherwise, false.

GetEnumerator

IEnumerator<KeyValuePair<string, Entity>> GetEnumerator()

ChangeKey

Changes the key associated with an existing entity in the collection. This also updates the entity's ID property to match the new key.

void ChangeKey(string oldKey, string newKey)

Parameters:

Name Type Description
oldKey System.String The current key of the entity.
newKey System.String The new key to assign to the entity.

Flush

Applies all the pending changes to the collection.

void Flush()