Table of Contents

Class Storage

Namespace
Csra.Services
Assembly
Csra.dll

StorageService - centralized persistent data storage. Uses type-specific dictionaries to avoid casting. Optimized for performance with O(1) lookups.

[Serializable]
public class Storage : IStorageService, IServiceBase
Inheritance
Storage
Implements
Inherited Members

Constructors

Storage()

protected Storage()

Properties

Count

Gets the number of key/value pairs contained in the storage.

public int Count { get; }

Property Value

int

Instance

public static IStorageService Instance { get; }

Property Value

IStorageService

Keys

Gets a collection containing the keys in the storage.

public IEnumerable<string> Keys { get; }

Property Value

IEnumerable<string>

Methods

AddOrUpdate<T>(string, T)

Adds a key/value pair to the storage if the key does not already exist, or updates the value for an existing key.

public void AddOrUpdate<T>(string key, T value)

Parameters

key string

They key to be added or whose value should be updated.

value T

The value of the element to add, or update.

Type Parameters

T

ContainsKey<T>(string)

Determines whether the storage contains the specified key for the given type.

public bool ContainsKey<T>(string key)

Parameters

key string

The key to locate in the storage.

Returns

bool

true if the storage contains an element with the specified key; otherwise, false.

Type Parameters

T

The type of the value to check.

Remove<T>(string)

Removes the value with the specified key from the storage for the given type.

public bool Remove<T>(string key)

Parameters

key string

The key of the element to remove.

Returns

bool

true if the element is successfully found and removed; otherwise false.

Type Parameters

T

The type of the value to remove.

Reset()

Initialize the service. This is called by the API when the service is first used.

public void Reset()

TryGetValue<T>(string, out T)

Gets the type-safe value associated with the specified key.

public bool TryGetValue<T>(string key, out T value)

Parameters

key string

The key of the value to get.

value T

When this methods returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed unintialized.

Returns

bool

true if the storage contains an element with the specified key; otherwise, false.

Type Parameters

T

The type of object to retrieve.