コード例 #1
0
        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();
            }
        }
コード例 #2
0
        /// <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());
        }
コード例 #3
0
ファイル: PausableTask.cs プロジェクト: gianlucaguran/ECSTest
        internal PausableTask()
        {
            _enumeratorWrap   = new EnumeratorWrapper();
            _coroutineWrapper = new SerialTaskCollection(1);

            Reset();
        }
コード例 #4
0
        /// <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());
        }
コード例 #5
0
        /// <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
        }
コード例 #6
0
ファイル: DataReaderExtensions.cs プロジェクト: MingLu8/Nemo
        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);
            }
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        internal static IEnumerator UnwrapEnumerator(IEnumerator enumerator)
        {
            EnumeratorWrapper wrapper = enumerator as EnumeratorWrapper;

            if (wrapper != null)
            {
                enumerator = wrapper.InnerEnumerator;
            }
            return(enumerator);
        }
コード例 #9
0
        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);
                }
            }
        }
コード例 #10
0
 public ChunkedEnumerable(EnumeratorWrapper <T> wrapper, int chunkSize, int start)
 {
     this.wrapper   = wrapper;
     this.chunkSize = chunkSize;
     this.start     = start;
 }
コード例 #11
0
 public ClonedEnumerator(EnumeratorWrapper enumerator, Node firstNode)
 {
     _Enumerator = enumerator;
     _Node       = firstNode;
 }