Beispiel #1
0
        internal bool ReadListInternal(string tablePath, Type itemType, ReadContext context, IList destList)
        {
            // find table
            Table table = FindTable(tablePath);

            if (table == null)
            {
                return(false);
            }

            // header parse
            var ttm = new TableToTypeMap(itemType);

            for (int col = 0; col < table.Columns; col++)
            {
                ttm.AddFieldColumn(table.GetColumnName(col));
            }

            int readRows = table.Rows;

            if (0 < context.readMaxRows && context.readMaxRows < table.Rows)
            {
                readRows = context.readMaxRows;
            }

            // rows parse
            for (int row = 0; row < readRows; row++)
            {
                object rowObj = Util.New(itemType);

                ttm.OnNewRow(rowObj);

                for (int col = 0; col < table.Columns; col++)
                {
                    string value = table.GetValue(row, col);
                    if (value != null)
                    {
                        bool ret = ttm.SetValue(rowObj, col, value);

                        // if the value is not handled, give oppotunity to a custom parser
                        if (ret == false && context.customParser != null)
                        {
                            context.customParser(rowObj, table.GetColumnName(col), value);
                        }
                    }
                }

                destList.Add(rowObj);
            }

            // set context result
            context.table = table;
            context.ttm   = ttm;

            return(true);
        }
Beispiel #2
0
        //////////////////////////////////////////////////////////////
        internal bool ReadListInternal(Type itemType, int readMaxRows, IList destList)
        {
            // header parse
            var ttm = new TableToTypeMap(itemType);

            for (int col = 0; col < mColumnCount; col++)
            {
                ttm.AddFieldColumn(GetColumnName(col));
            }

            int readRows = mRowCount;

            if (0 < readMaxRows && readMaxRows < readRows)
            {
                readRows = readMaxRows;
            }

            // rows parse
            for (int row = 0; row < readRows; row++)
            {
                object rowObj = Util.New(itemType);

                ttm.OnNewRow(rowObj);

                for (int col = 0; col < mColumnCount; col++)
                {
                    string value = GetValue(row, col);
                    if (value != null)
                    {
                        bool ret = ttm.SetValue(rowObj, col, value);
                    }
                }

                destList.Add(rowObj);
            }

            return(true);
        }