You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using Connected.Interop;
|
|
|
|
|
|
|
|
|
|
namespace Connected.Caching;
|
|
|
|
|
|
|
|
|
|
internal class EntryEnumerator<T> : IEnumerator<T>
|
|
|
|
|
{
|
|
|
|
|
public EntryEnumerator(ConcurrentDictionary<string, IEntry> items)
|
|
|
|
|
{
|
|
|
|
|
Items = items;
|
|
|
|
|
Index = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int Count => Items.Count;
|
|
|
|
|
private int Index { get; set; }
|
|
|
|
|
private ConcurrentDictionary<string, IEntry> Items { get; }
|
|
|
|
|
|
|
|
|
|
public T Current => TypeConversion.TryConvert(Items.ElementAt(Index).Value.Instance, out T result) ? result : default;
|
|
|
|
|
|
|
|
|
|
object IEnumerator.Current => Current;
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool MoveNext()
|
|
|
|
|
{
|
|
|
|
|
if (Index < Count - 1)
|
|
|
|
|
{
|
|
|
|
|
Index++;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
|
|
|
|
Index = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|