private static void PrintData(LevelConfigData data) { var fields = data.GetType().GetFields(); foreach (FieldInfo field in fields) { object obj = field.GetValue(data); Console.WriteLine(field.Name + "\t\t" + obj); } }
public string ObjToCsv(IDictionary <string, int> dict, LevelConfigData data) { string[] items = new string[dict.Count]; FieldInfo[] fields = data.GetType().GetFields(); //int idx = 0; for (int idx = 0; idx < fields.Length; idx++) { FieldInfo field = fields[idx]; string key = field.Name; object val = field.GetValue(data); string txt = val.ToString(); if (field.FieldType == typeof(Boolean)) { txt = txt.ToUpper(); } int lookd = dict[key]; items[lookd] = txt; } return(String.Join(DELIM, items)); }
public LevelConfigData CsvToObj(IDictionary <string, int> dict, string line) { string[] items = line.Split(DELIM); LevelConfigData data = new LevelConfigData(); FieldInfo[] fields = data.GetType().GetFields(); //int idx = 0; for (int idx = 0; idx < fields.Length; idx++) { string item = items[idx]; FieldInfo field = fields[idx]; string key = field.Name; int value = dict[key]; // TODO pad LevelNo with '0' when build CSV var conv = Convert.ChangeType(item, field.FieldType); fields[idx].SetValue(data, conv); } return(data); }