From 0804297eed076bd59871940eb80358ac53e05c6a Mon Sep 17 00:00:00 2001 From: jkpete <1031139173@qq.com> Date: Mon, 7 Oct 2024 18:16:00 +0800 Subject: [PATCH] fixed bugs csv-GetAll --- Example/UsingTest/Script/EGSaveTest.cs | 25 ++++++++++++++----- .../EGFramework/Module/SaveTools/EGCsvSave.cs | 4 +-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Example/UsingTest/Script/EGSaveTest.cs b/Example/UsingTest/Script/EGSaveTest.cs index 5594152..f1135ad 100644 --- a/Example/UsingTest/Script/EGSaveTest.cs +++ b/Example/UsingTest/Script/EGSaveTest.cs @@ -25,12 +25,25 @@ namespace EGFramework.Examples.Test{ csvSave.InitSaveFile("SaveData/TestCsv.csv"); // Customer testData = csvSave.GetData("",1); // GD.Print("Name = "+testData.Name +" || ID = "+testData.Id); - Customer testData = new Customer(){ - Id = 1008, - Name = "AddDataDefault", - IsActive = true - }; - csvSave.SetData("",testData,2); + // Customer testData = new Customer(){ + // Id = 1008, + // Name = "AddDataDefault", + // IsActive = true + // }; + // csvSave.SetData("",testData,2) + + IEnumerable allResult = csvSave.GetAll(""); + GD.Print("Get result " + allResult.Count()); + foreach(Customer customer in allResult){ + GD.Print(customer.Id +"|" + customer.Name); + } + + // System.Linq.Expressions.Expression> expr = i => i.Id < 5; + // IEnumerable linqResult = csvSave.FindData("",expr); + // GD.Print("Find result " + linqResult.Count()); + // foreach(Customer customer in linqResult){ + // GD.Print(customer.Name); + // } // GD.Print(typeof(Customer)); // Type type = typeof(Customer); diff --git a/addons/EGFramework/Module/SaveTools/EGCsvSave.cs b/addons/EGFramework/Module/SaveTools/EGCsvSave.cs index 0538205..c7a7d6c 100644 --- a/addons/EGFramework/Module/SaveTools/EGCsvSave.cs +++ b/addons/EGFramework/Module/SaveTools/EGCsvSave.cs @@ -165,19 +165,19 @@ namespace EGFramework // throw new NotImplementedException(); List DataList = new List(); for (int dataID = 0; dataID < CsvDataBlock.Count(); dataID++){ + TData data = new TData(); foreach(PropertyInfo property in typeof(TData).GetProperties()){ CsvParamAttribute csvParam = property.GetCustomAttribute(); if(csvParam != null && CsvDataHeader.ContainsKey(csvParam._name)){ string valueStr = CsvDataBlock[dataID][CsvDataHeader[csvParam._name]]; - TData data = new TData(); if(property.PropertyType==typeof(string)){ property.SetValue(data,valueStr); }else{ property.SetValue(data,Convert.ChangeType(valueStr,property.PropertyType)); } - DataList.Add(data); } } + DataList.Add(data); } TypeDataContainer.Register(DataList); return DataList;