forked from Kinnara/ModernWpf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoopingSelectorDataSource.cs
107 lines (85 loc) · 2.38 KB
/
LoopingSelectorDataSource.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections;
using System.Collections.Generic;
namespace ModernWpf.MahApps
{
internal class LoopingSelectorDataSource : IList
{
private const int RepeatCount = 1000;
private readonly List<int> _source;
public LoopingSelectorDataSource(IEnumerable<int> source)
{
_source = new List<int>(source);
}
public object this[int index]
{
get
{
if (index < 0 || index >= Count)
{
throw new IndexOutOfRangeException();
}
return _source[index % _source.Count];
}
set => throw new NotImplementedException();
}
public bool IsFixedSize => true;
public bool IsReadOnly => true;
public int Count => _source.Count * RepeatCount;
public int SourceCount => _source.Count;
public bool IsSynchronized => false;
public object SyncRoot => this;
public int Add(object value)
{
throw new NotImplementedException();
}
public void Clear()
{
throw new NotImplementedException();
}
public bool Contains(object value)
{
if (value is int item)
{
return _source.Contains(item);
}
return false;
}
public void CopyTo(Array array, int index)
{
throw new NotImplementedException();
}
public IEnumerator GetEnumerator()
{
for (int i = 0; i < Count; i++)
{
yield return _source[i % _source.Count];
}
}
public int IndexOf(object value)
{
int index = -1;
if (value is int item)
{
index = _source.IndexOf(item);
}
if (index > -1)
{
index += _source.Count * (RepeatCount / 2);
}
return index;
}
public void Insert(int index, object value)
{
throw new NotImplementedException();
}
public void Remove(object value)
{
throw new NotImplementedException();
}
public void RemoveAt(int index)
{
throw new NotImplementedException();
}
}
}