public static string SerializeToJsonString(OIDClientSerializableMessage obj) { Dictionary<string, object> data = SerializeToDictionary(obj); return SerializeToJsonString(data); }
public static string SerializeToQueryString(OIDClientSerializableMessage obj) { string queryString = ""; Dictionary<string, object> data = SerializeToDictionary(obj); foreach (KeyValuePair<string, object> entry in data) { string value = entry.Value.ToString(); if (typeof(OIDClientSerializableMessage).IsAssignableFrom(entry.Value.GetType())) { OIDClientSerializableMessage propertyValue = (OIDClientSerializableMessage)entry.Value; value = SerializeToQueryString(propertyValue); } else if (entry.Value.GetType().IsGenericType) { dynamic dValue = entry.Value; if (GetType(entry.Value.GetType()) == typeof(List<>)) { value = ""; foreach (object val in dValue) { value += (value == "") ? "" : " "; if (val.GetType() == typeof(ResponseType)) { string enumval = ((ResponseType)val).ToString(); FieldInfo fi = typeof(ResponseType).GetField(enumval); EnumMemberAttribute[] attributes = (EnumMemberAttribute[])fi.GetCustomAttributes(typeof(EnumMemberAttribute), false); value += (attributes.Length > 0) ? attributes[0].Value : enumval; } else if (val.GetType() == typeof(MessageScope)) { string enumval = ((MessageScope)val).ToString(); FieldInfo fi = typeof(MessageScope).GetField(enumval); EnumMemberAttribute[] attributes = (EnumMemberAttribute[])fi.GetCustomAttributes(typeof(EnumMemberAttribute), false); value += (attributes.Length > 0) ? attributes[0].Value : enumval; } else { value += val.ToString(); } } } else if (GetType(entry.Value.GetType()) == typeof(Dictionary<,>)) { value = "{ "; foreach (string val in dValue.Keys) { value += "\"" + val + "\": " + SerializeToJsonString(dValue[val]) + ","; } value = value.TrimEnd(','); value += " }"; } } queryString += entry.Key + "=" + Uri.EscapeDataString(value) + "&"; } return queryString.TrimEnd('&'); }