Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace Cache
- {
- public class CacheHandler<T> : IEnumerator
- {
- private int _index = -1;
- private Func<List<T>> _refresh { get; set; }
- private Action<T> _insert;
- public List<T> Items { get; set; }
- public CacheHandler(Func<List<T>> refresh)
- {
- _refresh = refresh;
- }
- public void Refresh()
- {
- Items = _refresh();
- }
- public bool MoveNext()
- {
- _index += 1;
- return _index < Items.Count;
- }
- public void Reset()
- {
- _index = 0;
- }
- public T this[int index]
- {
- get
- {
- if (Items == null)
- Refresh();
- if (Items == null || index < 0 || Items.Count == index)
- return default(T);
- return Items[index];
- }
- }
- public int Count => (Items ?? new List<T>()).Count;
- public int Length => Count;
- public object Current
- {
- get
- {
- return Items[_index];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement