Advertisement
Guest User

Untitled

a guest
May 2nd, 2021
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. public class BJsonEnumerable<T> : IEnumerator<T>, IEnumerable<T> where T : class
  2. {
  3. public IEnumerator<T> GetEnumerator()
  4. {
  5. if (check) new BJsonEnumerable<T>(this.bsonData, this.maxOffset);
  6. return this;
  7. }
  8.  
  9.  
  10. ILiteQueryable<T> bsonData;
  11. IBsonDataReader bsonDataReader;
  12. bool check;
  13. public BJsonEnumerable(ILiteQueryable<T> bsonData, int maxOffset = 10000)
  14. {
  15. this.bsonData = bsonData;
  16. check = false;
  17. this.maxOffset = maxOffset;
  18. }
  19. public void Begin()
  20. {
  21. bsonDataReader = bsonData.Offset(this.offset).ExecuteReader();
  22.  
  23. }
  24.  
  25. int offset = 0;
  26. int abstract_offset = 0;
  27. int maxOffset;
  28. public T Current { get { return current; } set { current = value; } }
  29. private T current;
  30.  
  31. object IEnumerator.Current { get { return current; } }
  32.  
  33.  
  34. public void Dispose()
  35. {
  36. this.current = null;
  37. this.bsonDataReader = null;
  38.  
  39. }
  40.  
  41. public bool MoveNext()
  42. {
  43.  
  44. this.check = true;
  45. if (bsonDataReader == null) Reset();
  46. bool read = bsonDataReader.Read();
  47. if (read == false)
  48. {
  49. this.current = default;
  50. return false;
  51. }
  52. var bJson = bsonDataReader.Current ;
  53.  
  54. string json = bJson.ToString();
  55. bJson.RawValue = null;
  56.  
  57. this.current = JsonConvert.DeserializeObject<T>(json);
  58. offset++;
  59. abstract_offset++;
  60. //if (abstract_offset > maxOffset)
  61. //{
  62. // abstract_offset = 0;
  63. // bsonDataReader.Dispose();
  64. // Begin();
  65. //}
  66. return read;
  67. }
  68.  
  69. public void Reset()
  70. {
  71. this.current = null;
  72. if (this.bsonDataReader == null) Begin();
  73.  
  74. }
  75.  
  76. IEnumerator IEnumerable.GetEnumerator()
  77. {
  78. if (check) new BJsonEnumerable<T>(this.bsonData, this.maxOffset);
  79. return this;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement