Table of Contents

Interface IUniqueIndex<TItem, TKey>

Namespace
AutoIndexCache
Assembly
AutoIndexCache.dll

Represents a unique index for cached items of the type TItem.

public interface IUniqueIndex<out TItem, TKey> where TItem : class

Type Parameters

TItem

The type of cache items indexed by the index.

TKey

The type of keys in the index.

Methods

ContainsKey(TKey?)

Determines whether this index contains the specified key.

bool ContainsKey(TKey? key)

Parameters

key TKey

The key to check.

Returns

bool

True if this index contains the specified key; otherwise, false.

Examples

var cache = new AutoIndexCache();
cache.Items<User>().Fill(this.LoadUsers());
var existsUser1 = cache.Items<User>().UniqueIndex(a => a.Id).ContainsKey(1);

Exceptions

ItemsListNotFilledYetException

This ItemsList<TItem> this index belongs to has not been filled with items yet.

DuplicateKeyException

Multiple cache items of the type TItem have the same key for this unique index.

GetItemOrDefault(TKey?)

Gets the cached item of the type TItem that satisfies the specified condition or default(TItem) if no such cache item was found.

TItem? GetItemOrDefault(TKey? condition)

Parameters

condition TKey

The condition the cache item to get must satisfy.

Returns

TItem

The cached item of the type TItem that satisfies the specified condition or default(TItem) if no such cache item was found.

Examples

var cache = new AutoIndexCache();
cache.Items<User>().Fill(this.LoadUsers());
var user1 = cache.Items<User>().UniqueIndex(a => a.Id).GetItemOrDefault(1);

Exceptions

ItemsListNotFilledYetException

This ItemsList<TItem> this index belongs to has not been filled with items yet.

DuplicateKeyException

Multiple cache items of the type TItem have the same key for this unique index.

GetKeys()

Gets the keys in this index.

IReadOnlyCollection<TKey?> GetKeys()

Returns

IReadOnlyCollection<TKey>

A read-only collection of the keys of this index.

Examples

var cache = new AutoIndexCache();
cache.Items<User>().Fill(this.LoadUsers());
var usersIds = cache.Items<User>().UniqueIndex(a => a.Id).GetKeys();

Exceptions

ItemsListNotFilledYetException

This ItemsList<TItem> this index belongs to has not been filled with items yet.

DuplicateKeyException

Multiple cache items of the type TItem have the same key for this unique index.