Iterator.cs 825 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace SharpCifs.Util.Sharpen
  5. {
  6. public interface ITerator
  7. {
  8. bool HasNext ();
  9. object Next ();
  10. void Remove ();
  11. }
  12. public abstract class Iterator<T> : IEnumerator<T>, ITerator
  13. {
  14. private T _lastValue;
  15. object ITerator.Next ()
  16. {
  17. return Next ();
  18. }
  19. public abstract bool HasNext ();
  20. public abstract T Next ();
  21. public abstract void Remove ();
  22. bool IEnumerator.MoveNext ()
  23. {
  24. if (HasNext ()) {
  25. _lastValue = Next ();
  26. return true;
  27. }
  28. return false;
  29. }
  30. void IEnumerator.Reset ()
  31. {
  32. throw new NotImplementedException ();
  33. }
  34. void IDisposable.Dispose ()
  35. {
  36. }
  37. T IEnumerator<T>.Current {
  38. get { return _lastValue; }
  39. }
  40. object IEnumerator.Current {
  41. get { return _lastValue; }
  42. }
  43. }
  44. }