public JsonValue ToJson(JsonSerializer serializer) { var useForClear = false; var obj = new JsonObject(); switch (Type) { case CustomFieldType.Text: if (Text == null) { useForClear = true; break; } obj["text"] = Text; break; case CustomFieldType.DropDown: if (Selected == null) { useForClear = true; break; } obj["idValue"] = Selected.Id; break; case CustomFieldType.CheckBox: if (Checked == null) { useForClear = true; break; } obj["checked"] = Checked.ToLowerString(); break; case CustomFieldType.DateTime: if (Date == null) { useForClear = true; break; } obj["date"] = serializer.Serialize(Date); break; case CustomFieldType.Number: if (Number == null) { useForClear = true; break; } obj["number"] = string.Format(CultureInfo.InvariantCulture, "{0}", Number); break; case CustomFieldType.Unknown: default: throw new ArgumentOutOfRangeException(); } return(useForClear ? (JsonValue)string.Empty : obj); }