public static IEnumerable <IEnumerable <T> > Chunk <T>(this IEnumerable <T> source, int chunksize) { if (chunksize < 1) { throw new InvalidOperationException(); } var wrapper = new EnumeratorWrapper <T>(source); int currentPos = 0; T ignore; try { wrapper.AddRef(); while (wrapper.Get(currentPos, out ignore)) { yield return(new ChunkedEnumerable <T>(wrapper, chunksize, currentPos)); currentPos += chunksize; } } finally { wrapper.RemoveRef(); } }
/// <summary> /// Reads a single escaped field data value from the source. The source must be currently positioned on the opening double quote of the field data. On return, the source is either at the end of the input or is positioned on the first character that is not part of the field data (past the closing double quote). /// </summary> /// <param name="source">The source from which to read.</param> /// <returns>The field data value.</returns> private string ReadEscapedFieldValue(EnumeratorWrapper <char> source) { var sb = new StringBuilder(); // Consume the '\"' character. source.MoveNext(); while (source.More) { var ch = source.Current; if (ch == '\"') { // A '\"' character within escaped field data may be the end of the escaped field data or it may be the first character of a 2DQUOTE escape sequence. source.MoveNext(); if (source.Done || source.Current != '\"') { // The '\"' was the end of the escaped field data. return(sb.ToString()); } } // Consume the next character of the field data. sb.Append(ch); source.MoveNext(); } // The while loop was exited by reaching the end of the source sequence, so publish the last FieldData token (with a warning, since the ending double quote was never found). Warning("Lexer: Last entry in file is not complete; check for file truncation."); return(sb.ToString()); }
internal PausableTask() { _enumeratorWrap = new EnumeratorWrapper(); _coroutineWrapper = new SerialTaskCollection(1); Reset(); }
/// <summary> /// Reads a single unescaped field data value from the source. The source must be currently positioned on the first character of the field data. On return, the source is either at the end of the input or is positioned on the first character that is not part of the field data. /// </summary> /// <param name="source">The source from which to read.</param> /// <returns>The field data value.</returns> private string ReadUnescapedFieldValue(EnumeratorWrapper <char> source) { var sb = new StringBuilder(); // Consume the first character of the field data. sb.Append(source.Current); source.MoveNext(); while (source.More) { var ch = source.Current; if (ch == this.fieldSeparator || ch == '\r' || ch == '\n') { // Unescaped field data can be terminated by a FieldSeparator or EndOfRecord. // Publish the FieldData token, but do not consume the characters for the FieldSeparator or EndOfRecord tokens. return(sb.ToString()); } // Consume the next character of the field data. sb.Append(ch); source.MoveNext(); } // The while loop was exited by reaching the end of the source sequence, so publish the last FieldData token. return(sb.ToString()); }
/// <summary> /// Creates the enumerator /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> protected IEnumerator <T> MakeEnumerator <T>() { var result = new EnumeratorWrapper <T>(_toWrap); return(result.IsValid ? result : new EnumeratorWrapper <T>(new T[0])); // fake no results }
private static IEnumerable <T> BuildEnumerable <T>(Func <bool> moveNext, Func <T> current) { var enumerator = new EnumeratorWrapper <T>(moveNext, current); foreach (var item in enumerator) { yield return(item); } }
private static IEnumerable <T> BuildEnumerable <T>( Func <bool> moveNext, Func <T> current) { var po = new EnumeratorWrapper <T>(moveNext, current); foreach (var s in po) { yield return(s); } }
internal static IEnumerator UnwrapEnumerator(IEnumerator enumerator) { EnumeratorWrapper wrapper = enumerator as EnumeratorWrapper; if (wrapper != null) { enumerator = wrapper.InnerEnumerator; } return(enumerator); }
public void IterationTest() { var testValues = new[] {1, 2, 3}; var enumerator = new List<int>(testValues.ToArray()).GetEnumerator(); using(var enumeratorWrapper = new EnumeratorWrapper<string>(enumerator, value => value.ToString())) { foreach(var testValue in testValues) { enumeratorWrapper.MoveNext(); Assert.AreEqual(testValue.ToString(CultureInfo.InvariantCulture), enumeratorWrapper.Current); } } }
public ChunkedEnumerable(EnumeratorWrapper <T> wrapper, int chunkSize, int start) { this.wrapper = wrapper; this.chunkSize = chunkSize; this.start = start; }
public ClonedEnumerator(EnumeratorWrapper enumerator, Node firstNode) { _Enumerator = enumerator; _Node = firstNode; }