public static T LoadObject <T>(JsonData json, T csObj) { List <string> properties = Comm.GetProperties(csObj); foreach (string key in properties) { if (json.Keys.Contains(key) && json[key] != null) { if (json[key].IsArray) { ArrayList list = new ArrayList(); for (int i = 0; i < json[key].Count; i++) { JsonData item = json[key][i]; if (item.IsString) { list.Add(item.ToString()); } else { list.Add(item.ToBinary()); } } Comm.SetPropertyValue(csObj, key, list); } else { Comm.SetPropertyValue(csObj, key, json[key]); } } } return(csObj); }
static JsonData SerializeJson(object csObj) { JsonData json = new JsonData(); List <string> properties = Comm.GetProperties(csObj); foreach (string key in properties) { object val = Comm.GetPropertyValue(csObj, key); if (val != null) { if (val.GetType().IsValueType || val.GetType() == typeof(string)) { json[key] = new JsonData(val); } else { json[key] = Serialize(val); } } } return(json); }