CSVSheet(string filePath, TextLine textLine) { Assert.IsTrue(textLine != null); this.filePath = filePath; using (var lines = textLine.GetEnumerator()) { lines.MoveNext(); string colNames = lines.Current; lines.MoveNext(); string colTypes = lines.Current; this.columnInfo = new ColumnInfo(colNames, colTypes, filePath); List<RowData> tempList = new List<RowData>(); while (lines.MoveNext()) { string line = lines.Current; if (!string.IsNullOrEmpty(line)) { var tokens = line.Split(','); var newRow = new RowData(tokens); Assert.IsTrue(newRow.IsValidInLength(columnInfo), string.Format("tokens.Length={0}, columnInfo.Length={1} in \n{2}", tokens.Length, columnInfo.Length, line)); int errIndex; Assert.IsTrue(newRow.IsValidInType(columnInfo, out errIndex), errIndex < 0 ? string.Empty : string.Format("Converting error: [{0}] to {1} in {2}", tokens[errIndex], columnInfo[errIndex].Value, filePath)); tempList.Add(newRow); } } rows = tempList; } }
TableGenerator(string resPath, string className) { TextAsset csvFile = Resources.Load(resPath) as TextAsset; Assert.IsTrue(csvFile != null, "File not found: " + resPath); TextLine textLine = new TextLine(csvFile.text); Assert.IsTrue(textLine != null); using (var lines = textLine.GetEnumerator()) { lines.MoveNext(); string colNames = lines.Current; lines.MoveNext(); string colTypes = lines.Current; this.columnInfo = new ColumnInfo(colNames, colTypes, resPath); } this.className = className; }