private void ReadNextRecord()
        {
            string currentLine = mAsyncReader.ReadNextLine();

            mLineNumber++;

            bool byPass = false;

            mLastRecord = null;

            LineInfo line = new LineInfo(currentLine);

            line.mReader = mAsyncReader;


            while (true)
            {
                if (currentLine != null)
                {
                    try
                    {
                        mTotalRecords++;

                        Type currType = mRecordSelector(this, currentLine);

                        line.ReLoad(currentLine);

                        if (currType != null)
                        {
                            RecordInfo info   = (RecordInfo)mRecordInfoHash[currType];
                            object[]   values = new object[info.mFieldCount];
                            mLastRecord = info.StringToRecord(line, values);

                            if (mLastRecord != null)
                            {
                                byPass = true;
                                return;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        switch (mErrorManager.ErrorMode)
                        {
                        case ErrorMode.ThrowException:
                            byPass = true;
                            throw;

                        case ErrorMode.IgnoreAndContinue:
                            break;

                        case ErrorMode.SaveAndContinue:
                            ErrorInfo err = new ErrorInfo();
                            err.mLineNumber    = mAsyncReader.LineNumber;
                            err.mExceptionInfo = ex;
                            //							err.mColumnNumber = mColumnNum;
                            err.mRecordString = currentLine;

                            mErrorManager.AddError(err);
                            break;
                        }
                    }
                    finally
                    {
                        if (byPass == false)
                        {
                            currentLine = mAsyncReader.ReadNextLine();
                            mLineNumber = mAsyncReader.LineNumber;
                        }
                    }
                }
                else
                {
                    mLastRecord = null;


                    if (mRecordInfo.mIgnoreLast > 0)
                    {
                        mFooterText = mAsyncReader.RemainingText;
                    }

                    try
                    {
                        mAsyncReader.Close();
                    }
                    catch
                    {
                    }

                    return;
                }
            }
        }
        /// <include file='MultiRecordEngine.docs.xml' path='doc/ReadStream/*'/>
        public object[] ReadStream(IRecordReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader", "The reader of the Stream can´t be null");
            }

            if (mRecordSelector == null)
            {
                throw new BadUsageException("The Recordselector can´t be null, please pass a not null Selector in the constructor.");
            }

            ResetFields();
            mHeaderText = String.Empty;
            mFooterText = String.Empty;

            ArrayList resArray = new ArrayList();

            using (ForwardReader freader = new ForwardReader(reader, mMultiRecordInfo[0].mIgnoreLast))
            {
                freader.DiscardForward = true;

                string currentLine, completeLine;

                mLineNumber = 1;

                completeLine = freader.ReadNextLine();
                currentLine  = completeLine;

#if !MINI
                ProgressHelper.Notify(mNotifyHandler, mProgressMode, 0, -1);
#endif
                int currentRecord = 0;

                if (mMultiRecordInfo[0].mIgnoreFirst > 0)
                {
                    for (int i = 0; i < mMultiRecordInfo[0].mIgnoreFirst && currentLine != null; i++)
                    {
                        mHeaderText += currentLine + StringHelper.NewLine;
                        currentLine  = freader.ReadNextLine();
                        mLineNumber++;
                    }
                }


                bool byPass = false;

                //			MasterDetails record = null;
                ArrayList tmpDetails = new ArrayList();

                LineInfo line = new LineInfo(currentLine);
                line.mReader = freader;

                while (currentLine != null)
                {
                    try
                    {
                        mTotalRecords++;
                        currentRecord++;

                        line.ReLoad(currentLine);

                        bool skip = false;
#if !MINI
                        ProgressHelper.Notify(mNotifyHandler, mProgressMode, currentRecord, -1);
                        skip = OnBeforeReadRecord(currentLine);
#endif

                        Type currType = mRecordSelector(this, currentLine);

                        if (currType != null)
                        {
                            RecordInfo info = (RecordInfo)mRecordInfoHash[currType];

                            if (skip == false)
                            {
                                object[] values = new object[info.mFieldCount];
                                object   record = info.StringToRecord(line, values);

#if !MINI
                                skip = OnAfterReadRecord(currentLine, record);
#endif

                                if (skip == false && record != null)
                                {
                                    resArray.Add(record);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        switch (mErrorManager.ErrorMode)
                        {
                        case ErrorMode.ThrowException:
                            byPass = true;
                            throw;

                        case ErrorMode.IgnoreAndContinue:
                            break;

                        case ErrorMode.SaveAndContinue:
                            ErrorInfo err = new ErrorInfo();
                            err.mLineNumber    = freader.LineNumber;
                            err.mExceptionInfo = ex;
                            //							err.mColumnNumber = mColumnNum;
                            err.mRecordString = completeLine;

                            mErrorManager.AddError(err);
                            break;
                        }
                    }
                    finally
                    {
                        if (byPass == false)
                        {
                            currentLine  = freader.ReadNextLine();
                            completeLine = currentLine;
                            mLineNumber  = freader.LineNumber;
                        }
                    }
                }

                if (mMultiRecordInfo[0].mIgnoreLast > 0)
                {
                    mFooterText = freader.RemainingText;
                }
            }
            return(resArray.ToArray());
        }