public void ToCsv() { var table = new DataTable(); for (int i = 0; i < 4; i++) { table.Columns.Add(new DataColumn { ColumnName = ((char)('a' + i)).ToString() }); } for (int r = 0; r < 2; r++) { DataRow row = table.NewRow(); row[0] = "0"; row[1] = "1"; row[2] = " 2"; row[3] = "\"3\""; table.Rows.Add(row); } string csv = CsvUtility.ToCsv(table); string expected = Resources.Load <TextAsset>("table0").text; Assert.NotNull(csv); Assert.AreEqual(expected, csv); }
void OnGUI() { if (GUILayout.Button("Save/Load Test")) { var dataArray = GenerateData(); var csv = CsvUtility.ToCsv(dataArray); System.IO.File.WriteAllText("CsvOutput/serialized.csv", csv); var deserialized = CsvUtility.FromCsv <Data>(csv); var csv2 = CsvUtility.ToCsv(deserialized); System.IO.File.WriteAllText("CsvOutput/serialized2.csv", csv2); Debug.Assert(csv == csv2); } if (GUILayout.Button("Ordered Save Test")) { var dataArray = GenerateData(); // 順序指定 string[] order = { "id", "boolValue", "charValue", "sbyteValue", "byteValue", "shortValue", "ushortValue", "NonExistance", "intValue", "uintValue", "longValue", "ulongValue", "floatValue", "doubleValue", "stringValue", "nonSerializedTypeValue", "serializedTypeValue", "arrayValue", "listValue", "nonSerializedPrivateField", "nonSerializedPublicField" }; var csv = CsvUtility.ToCsv(dataArray, order); System.IO.File.WriteAllText("CsvOutput/serializedOrdered.csv", csv); var deserialized = CsvUtility.FromCsv <Data>(csv); var csv2 = CsvUtility.ToCsv(deserialized, order); System.IO.File.WriteAllText("CsvOutput/serializedOrdered2.csv", csv2); Debug.Assert(csv == csv2); } GUILayout.Label(log); }