-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElementEnumerator.cs
More file actions
73 lines (62 loc) · 1.77 KB
/
ElementEnumerator.cs
File metadata and controls
73 lines (62 loc) · 1.77 KB
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
/******************************************************************/
/// <copyright file="ElementEnumerator.cs" company="Sharpro">
/// Copyright (c) 2018 All Rights Reserved
/// </copyright>
/// <author>Jarosław Mielewski</author>
/// <date>16:09</date>
/******************************************************************/
namespace _2_interfejsy_kolekcje
{
using System;
using System.Collections;
using System.Collections.Generic;
public class ElementEnumerator : IEnumerator<IElement>
{
private List<IElement> _elements;
private int _position;
public IElement Current
{
get
{
try
{
return _elements[_position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
object IEnumerator.Current => _elements[_position];
public ElementEnumerator()
{
_position = -1;
_elements = new List<IElement>();
for (int i = 1; i < 8; i++)
{
_elements.Add(new CollectionElement(i.ToString(), i));
}
}
public void Dispose()
{
_position = -1;
}
public bool MoveNext()
{
return (++_position < _elements.Count);
}
public void Reset()
{
_position = -1;
}
public bool MovePrevious()
{
return (--_position > -1);
}
public void Insert(IElement element)
{
_elements[_position + 1] = element;
}
}
}