Exemplo n.º 1
0
        public void Load(Stream stream)
        {
            m_ColumnHeaders = null;
            Rows            = null;

            StreamReader reader = new StreamReader(stream);

            string strLine;
            int    findIndex;

            while (reader.EndOfStream == false)
            {
                strLine = reader.ReadLine();
                if (string.IsNullOrEmpty(strLine.Trim()) == true)
                {
                    break;
                }

                string        data;
                List <string> datas = new List <string>();

                for (int lastFindIndex = 0; lastFindIndex < strLine.Length;)
                {
                    findIndex = strLine.IndexOfAny(delimiter, lastFindIndex);
                    if (findIndex == -1)
                    {
                        data = strLine.Substring(lastFindIndex);
                        datas.Add(data);
                        break;
                    }
                    else
                    {
                        if (strLine[findIndex] == '\"')
                        {
                            do
                            {
                                findIndex = strLine.IndexOf('\"', findIndex + 1);
                            } while (strLine[findIndex - 1] != '\\');
                            findIndex = strLine.IndexOf('m');
                        }
                        data          = strLine.Substring(lastFindIndex, findIndex - lastFindIndex);
                        lastFindIndex = findIndex + 1;
                    }

                    datas.Add(data);
                }
                RowData _RowData = new RowData(datas);

                if (m_ColumnHeaders == null)
                {
                    m_ColumnHeaders = new Dictionary <string, int>();
                    Rows            = new List <RowData>();

                    for (int i = 0; i < _RowData.Count; ++i)
                    {
                        m_ColumnHeaders.Add(_RowData.GetData(i), i);
                    }
                }
                else
                {
                    Rows.Add(_RowData);
                }
            }
        }