Browse Source

fixed bugs csv-GetAll

master
jkpete 2 months ago
parent
commit
0804297eed
  1. 25
      Example/UsingTest/Script/EGSaveTest.cs
  2. 4
      addons/EGFramework/Module/SaveTools/EGCsvSave.cs

25
Example/UsingTest/Script/EGSaveTest.cs

@ -25,12 +25,25 @@ namespace EGFramework.Examples.Test{ @@ -25,12 +25,25 @@ namespace EGFramework.Examples.Test{
csvSave.InitSaveFile("SaveData/TestCsv.csv");
// Customer testData = csvSave.GetData<Customer>("",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<Customer> allResult = csvSave.GetAll<Customer>("");
GD.Print("Get result " + allResult.Count());
foreach(Customer customer in allResult){
GD.Print(customer.Id +"|" + customer.Name);
}
// System.Linq.Expressions.Expression<Func<Customer, bool>> expr = i => i.Id < 5;
// IEnumerable<Customer> linqResult = csvSave.FindData<Customer>("",expr);
// GD.Print("Find result " + linqResult.Count());
// foreach(Customer customer in linqResult){
// GD.Print(customer.Name);
// }
// GD.Print(typeof(Customer));
// Type type = typeof(Customer);

4
addons/EGFramework/Module/SaveTools/EGCsvSave.cs

@ -165,19 +165,19 @@ namespace EGFramework @@ -165,19 +165,19 @@ namespace EGFramework
// throw new NotImplementedException();
List<TData> DataList = new List<TData>();
for (int dataID = 0; dataID < CsvDataBlock.Count(); dataID++){
TData data = new TData();
foreach(PropertyInfo property in typeof(TData).GetProperties()){
CsvParamAttribute csvParam = property.GetCustomAttribute<CsvParamAttribute>();
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;

Loading…
Cancel
Save