public JsonObject SerializeEnum(Enum e) { JsonObject json = new JsonObject(); String description = e.GetDescription(); String name = e.GetName(); Int32 position = e.GetPosition(); String value = e.GetValue(); if (description != null) { json["Description"] = new JsonString { Value = description } } ; else { json["Description"] = new JsonNull(); } if (name != null) { json["Name"] = new JsonString { Value = name } } ; else { json["Name"] = new JsonNull(); } if (position > 0) { json["Position"] = new JsonNumber { Value = position } } ; else { json["Position"] = new JsonNull(); } if (value != null) { json["Value"] = new JsonString { Value = value } } ; else { json["Value"] = new JsonNull(); } return(json); }
public JsonProperty SerializeProperty(PropertyInfo property, Object obj) { JsonValue json; String key = property.Name; Object value = property.GetValue(obj); if (value == null) { json = new JsonNull(); } else if (property.GetType().IsEnum) { json = this.SerializeEnum((Enum)value); } else if (property.PropertyType.Name == "Currency") { json = new JsonString { Value = ((Currency)value).ToString() }; } else if (property.PropertyType.Name == "Percent") { json = new JsonString { Value = ((Percent)value).ToString() }; } else { json = this.SerializeObject(value); } return(new JsonProperty { Key = key, Value = json }); }