ArrayEnumerator.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // RichTextKit
  2. // Copyright © 2019-2020 Topten Software. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. // not use this product except in compliance with the License. You may obtain
  6. // a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. // License for the specific language governing permissions and limitations
  14. // under the License.
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.Text;
  19. namespace Topten.RichTextKit
  20. {
  21. class ArraySliceEnumerator<T> : IEnumerator<T>, IEnumerator
  22. {
  23. public ArraySliceEnumerator(T[] arr, int start, int length)
  24. {
  25. _arr = arr;
  26. _start = start;
  27. _end = start + length;
  28. _current = _start - 1;
  29. }
  30. T[] _arr;
  31. int _start;
  32. int _end;
  33. int _current;
  34. public T Current
  35. {
  36. get
  37. {
  38. if (_current < _end)
  39. return _arr[_current];
  40. else
  41. return default(T);
  42. }
  43. }
  44. object IEnumerator.Current => Current;
  45. public bool MoveNext()
  46. {
  47. if (_current < _end)
  48. _current++;
  49. return _current < _end;
  50. }
  51. public void Reset()
  52. {
  53. _current = _start - 1;
  54. }
  55. public void Dispose()
  56. {
  57. }
  58. }
  59. }