public static JToken ConvertObjectsToJToken(object[] p_objects, SerializeGroup.Type[] p_groups) { JArray jArray = new JArray(); foreach(object p_object in p_objects) jArray.Add(ConvertObjectToJToken(p_object, p_groups)); return jArray; }
public static JToken ConvertObjectToJToken(object p_object, SerializeGroup.Type[] p_groups) { JObject jToken = (JObject)ConvertObjectToJToken(p_object); foreach(PropertyInfo property in p_object.GetType().GetProperties(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance)) { foreach(object attribute in property.GetCustomAttributes(true)) { if(attribute.GetType().IsAssignableFrom(typeof(SerializeGroup))) { SerializeGroup group = (SerializeGroup)attribute; bool hasAttribute = false; foreach(SerializeGroup.Type groupType in p_groups) { if(group.groupType == groupType) hasAttribute = true; } // Remove the property? if(!hasAttribute) jToken.Remove(property.Name); } } } foreach(FieldInfo field in p_object.GetType().GetFields(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance)) { foreach(object attribute in field.GetCustomAttributes(true)) { if(attribute.GetType().IsAssignableFrom(typeof(SerializeGroup))) { SerializeGroup group = (SerializeGroup)attribute; bool hasAttribute = false; foreach(SerializeGroup.Type groupType in p_groups) { if(group.groupType == groupType) hasAttribute = true; } // Remove the property? if(!hasAttribute) jToken.Remove(field.Name); } } } return (JToken)jToken; }
public static string ConvertObjectToString(object p_object, SerializeGroup.Type[] p_groups) { //return JsonConvert.SerializeObject(p_object); return JsonTools.ConvertObjectToJToken(p_object, p_groups).ToString(); }
public static JToken ConvertObjectToJToken(object p_object, SerializeGroup.Type p_group) { return ConvertObjectToJToken(p_object, new SerializeGroup.Type[]{p_group}); }