Skip to content

Commit 5c09f58

Browse files
committed
Implement SeparatedSyntaxListWrapper<TNode>.GetEnumerator()
1 parent cac5bf7 commit 5c09f58

1 file changed

Lines changed: 50 additions & 12 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SeparatedSyntaxListWrapper`1.cs

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ public override bool Equals(object obj)
9797

9898
public Enumerator GetEnumerator()
9999
{
100-
throw new NotImplementedException();
100+
return new Enumerator(this);
101101
}
102102

103103
IEnumerator<TNode> IEnumerable<TNode>.GetEnumerator()
104104
{
105-
throw new NotImplementedException();
105+
return this.GetEnumerator();
106106
}
107107

108108
IEnumerator IEnumerable.GetEnumerator()
@@ -148,34 +148,72 @@ IEnumerator IEnumerable.GetEnumerator()
148148

149149
public override abstract string ToString();
150150

151-
public struct Enumerator
151+
public struct Enumerator : IEnumerator<TNode>
152152
{
153-
public TNode Current
153+
private readonly SeparatedSyntaxListWrapper<TNode> wrapper;
154+
private int index;
155+
private TNode current;
156+
157+
public Enumerator(SeparatedSyntaxListWrapper<TNode> wrapper)
154158
{
155-
get
156-
{
157-
throw new NotImplementedException();
158-
}
159+
this.wrapper = wrapper;
160+
this.index = -1;
161+
this.current = default(TNode);
159162
}
160163

164+
public TNode Current => this.current;
165+
166+
object IEnumerator.Current => this.Current;
167+
161168
public override bool Equals(object obj)
162169
{
163-
throw new NotImplementedException();
170+
Enumerator? otherOpt = obj as Enumerator?;
171+
if (!otherOpt.HasValue)
172+
{
173+
return false;
174+
}
175+
176+
Enumerator other = otherOpt.GetValueOrDefault();
177+
return other.wrapper == this.wrapper
178+
&& other.index == this.index;
164179
}
165180

166181
public override int GetHashCode()
167182
{
168-
throw new NotImplementedException();
183+
if (this.wrapper == null)
184+
{
185+
return 0;
186+
}
187+
188+
return this.wrapper.GetHashCode() ^ this.index;
189+
}
190+
191+
public void Dispose()
192+
{
169193
}
170194

171195
public bool MoveNext()
172196
{
173-
throw new NotImplementedException();
197+
if (this.index < -1)
198+
{
199+
return false;
200+
}
201+
202+
if (this.index == this.wrapper.Count - 1)
203+
{
204+
this.index = int.MinValue;
205+
return false;
206+
}
207+
208+
this.index++;
209+
this.current = this.wrapper[this.index];
210+
return true;
174211
}
175212

176213
public void Reset()
177214
{
178-
throw new NotImplementedException();
215+
this.index = -1;
216+
this.current = default(TNode);
179217
}
180218
}
181219

0 commit comments

Comments
 (0)