-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSimpleRepository.cs
49 lines (42 loc) · 1.06 KB
/
SimpleRepository.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Date: 28.8.2014, Time: 0:01 */
using System;
using System.Collections.Generic;
namespace AlbLib
{
public class SimpleRepository<T> : Repository<T> where T : IGameResource
{
private readonly Func<int,T> getter;
private readonly Func<IEnumerable<KeyValuePair<int,T>>> enumerator;
public SimpleRepository(Func<int,T> getter, Func<IList<T>> all)
{
this.getter = getter;
this.enumerator = ()=>AllEnumerator(all);
}
public SimpleRepository(Func<int,T> getter, Func<IEnumerable<KeyValuePair<int,T>>> enumerator)
{
this.getter = getter;
this.enumerator = enumerator;
}
public override PathInfo Path{
get{
return null;
}
}
protected override T GetEntry(int id)
{
return getter(id);
}
private IEnumerable<KeyValuePair<int, T>> AllEnumerator(Func<IList<T>> all)
{
IList<T> list = all();
for(int i = 0; i < list.Count; i++)
{
yield return new KeyValuePair<int,T>(i+1,list[i]);
}
}
protected override IEnumerable<KeyValuePair<int, T>> GetPairEnumerator()
{
return enumerator();
}
}
}