private static SerializeComplexTypeProperties ( object value ) : string | ||
value | object | |
Результат | string |
public static string SerializeComplexType(object value) { StringBuilder json = new StringBuilder(); json.Append("{"); json.Append(JsonConverter.SerializeComplexTypeProperties(value)); json.Append("}"); return(json.ToString()); }
private static string SerializeComplexTypeProperties(object value) { Type type = value.GetType(); StringBuilder json = new StringBuilder(); PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); bool first = true; for (int i = 0; i < properties.Length; i++) { PropertyInfo property = properties[i]; object propertyValue = property.GetValue(value, null); if (IsConsideredNull(propertyValue)) { continue; } if (!first) { json.Append(","); } else { first = false; } if (property.ContainsAttribute <MergePropertiesAttribute>()) { json.Append(JsonConverter.SerializeComplexTypeProperties(propertyValue)); } else { string attributeName = StringUtils.ToCamelCase(property.Name); json.AppendFormat("{0}:{1}", attributeName, JsonConverter.SerializeObject(propertyValue)); } } return(json.ToString()); }