public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteStartObject(); IPageResponse message = value as IPageResponse; if (message != null) { writer.WritePropertyName("draw"); writer.WriteValue(message.Draw); writer.WritePropertyName("recordsTotal"); writer.WriteValue(message.TotalRecords); writer.WritePropertyName("recordsFiltered"); writer.WriteValue(message.TotalFilteredRecords); writer.WritePropertyName("data"); serializer.Serialize(writer, message.Data); if (!string.IsNullOrWhiteSpace(message.Error)) { writer.WritePropertyName("error"); writer.WriteValue(message.Error); } } JsonConvertHelper.WriteJson(message, writer, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IPageResponse)).Select(x => x.Name).Contains(prop.Name) || JsonConvertHelper.GetPropertiesFromType(typeof(IPageResponse <>)).Select(x => x.Name).Contains(prop.Name)); writer.WriteEndObject(); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteStartObject(); IPageResponse message = value as IPageResponse; if (message != null) { writer.WritePropertyName("sEcho"); writer.WriteValue(message.Draw); writer.WritePropertyName("iTotalRecords"); writer.WriteValue(message.TotalRecords); writer.WritePropertyName("iTotalDisplayRecords"); writer.WriteValue(message.TotalFilteredRecords); writer.WritePropertyName("aaData"); serializer.Serialize(writer, message.Data); } JsonConvertHelper.WriteJson(message, writer, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IPageResponse)).Select(x => x.Name).Contains(prop.Name) || JsonConvertHelper.GetPropertiesFromType(typeof(IPageResponse <>)).Select(x => x.Name).Contains(prop.Name)); writer.WriteEndObject(); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteStartObject(); IFilterRequest message = value as IFilterRequest; if (message != null) { writer.WritePropertyName("draw"); writer.WriteValue(message.Draw); writer.WritePropertyName("start"); writer.WriteValue(message.Start); writer.WritePropertyName("length"); writer.WriteValue(message.Length); if (!string.IsNullOrWhiteSpace(message.Search.Value)) { writer.WritePropertyName("search[value]"); writer.WriteValue(message.Search.Value); writer.WritePropertyName("search[regex]"); writer.WriteValue(message.Search.IsRegex); } for (int i = 0; i < message.Sort.Count; i++) { writer.WritePropertyName(string.Format("order[{0}][column]", i)); writer.WriteValue(message.Sort[i].Column); writer.WritePropertyName(string.Format("order[{0}][dir]", i)); writer.WriteValue(message.Sort[i].Direction.AsString()); } foreach (KeyValuePair <int, IColumn> column in message.Columns.OrderBy(x => x.Key)) { writer.WritePropertyName(string.Format("columns[{0}][data]", column.Key)); writer.WriteValue(column.Value.Data); writer.WritePropertyName(string.Format("columns[{0}][name]", column.Key)); writer.WriteValue(column.Value.Name); writer.WritePropertyName(string.Format("columns[{0}][searchable]", column.Key)); writer.WriteValue(column.Value.Searchable); writer.WritePropertyName(string.Format("columns[{0}][orderable]", column.Key)); writer.WriteValue(column.Value.Sortable); if (!string.IsNullOrWhiteSpace(column.Value.Search.Value)) { writer.WritePropertyName(string.Format("columns[{0}][search][value]", column.Key)); writer.WriteValue(column.Value.Search.Value); writer.WritePropertyName(string.Format("columns[{0}][search][regex]", column.Key)); writer.WriteValue(column.Value.Search.IsRegex); } } } JsonConvertHelper.WriteJson(message, writer, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IFilterRequest)).Select(x => x.Name).Contains(prop.Name)); writer.WriteEndObject(); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { writer.WriteStartObject(); IFilterRequest message = value as IFilterRequest; if (message != null) { writer.WritePropertyName("sEcho"); writer.WriteValue(message.Draw); writer.WritePropertyName("iDisplayStart"); writer.WriteValue(message.Start); writer.WritePropertyName("iDisplayLength"); writer.WriteValue(message.Length); if (!string.IsNullOrWhiteSpace(message.Search.Value)) { writer.WritePropertyName("sSearch"); writer.WriteValue(message.Search.Value); writer.WritePropertyName("bEscapeRegex"); writer.WriteValue(message.Search.IsRegex); } writer.WritePropertyName("iColumns"); writer.WriteValue(message.Columns.Count); writer.WritePropertyName("iSortingCols"); writer.WriteValue(message.Sort.Count); for (int i = 0; i < message.Sort.Count; i++) { writer.WritePropertyName("iSortCol_" + i); writer.WriteValue(message.Sort[i].Column); writer.WritePropertyName("sSortDir_" + i); writer.WriteValue(message.Sort[i].Direction.AsString()); } foreach (KeyValuePair <int, IColumn> column in message.Columns.OrderBy(x => x.Key)) { writer.WritePropertyName("mDataProp_" + column.Key); writer.WriteValue(column.Value.Data); writer.WritePropertyName("bSearchable_" + column.Key); writer.WriteValue(column.Value.Searchable); writer.WritePropertyName("bSortable_" + column.Key); writer.WriteValue(column.Value.Sortable); if (!string.IsNullOrWhiteSpace(column.Value.Search.Value)) { writer.WritePropertyName("sSearch_" + column.Key); writer.WriteValue(column.Value.Search.Value); writer.WritePropertyName("bRegex_" + column.Key); writer.WriteValue(column.Value.Search.IsRegex); } } } JsonConvertHelper.WriteJson(message, writer, serializer, prop => JsonConvertHelper.GetPropertiesFromType(typeof(IFilterRequest)).Select(x => x.Name).Contains(prop.Name)); writer.WriteEndObject(); }