Ejemplo n.º 1
0
 public CSVRow(CSVTable table)
 {
     this.m_table     = table;
     this.m_rowOffset = table.GetColumnRowCount();
 }
Ejemplo n.º 2
0
        public void Load(string[] lines)
        {
            this.m_table = new CSVTable(this, lines.Length);

            if (lines.Length >= 2)
            {
                LogicArrayList <string> columnNames = this.ParseLine(lines[0]);
                LogicArrayList <string> columnTypes = this.ParseLine(lines[1]);

                for (int i = 0; i < columnNames.Size(); i++)
                {
                    this.m_table.AddColumn(columnNames[i]);
                }

                for (int i = 0; i < columnTypes.Size(); i++)
                {
                    string type       = columnTypes[i];
                    int    columnType = -1;

                    if (!string.IsNullOrEmpty(type))
                    {
                        if (string.Equals(type, "string", StringComparison.OrdinalIgnoreCase))
                        {
                            columnType = 0;
                        }
                        else if (string.Equals(type, "int", StringComparison.OrdinalIgnoreCase))
                        {
                            columnType = 1;
                        }
                        else if (string.Equals(type, "boolean", StringComparison.OrdinalIgnoreCase))
                        {
                            columnType = 2;
                        }
                        else
                        {
                            Debugger.Error(string.Format("Invalid column type '{0}', column name {1}, file {2}. Expecting: int/string/boolean.", columnTypes[i], columnNames[i], this.m_fileName));
                        }
                    }

                    this.m_table.AddColumnType(columnType);
                }

                this.m_table.ValidateColumnTypes();

                if (lines.Length > 2)
                {
                    for (int i = 2; i < lines.Length; i++)
                    {
                        LogicArrayList <string> values = this.ParseLine(lines[i]);

                        if (values.Size() > 0)
                        {
                            if (!string.IsNullOrEmpty(values[0]))
                            {
                                this.m_table.CreateRow();
                            }

                            for (int j = 0; j < values.Size(); j++)
                            {
                                this.m_table.AddAndConvertValue(values[j], j);
                            }
                        }
                    }
                }
            }
        }