private static JsonWriter Write(this JsonWriter jsonWriter, IJsonView jsonView, DataRow dataRow, Model model) { jsonWriter.WriteStartObject(); var jsonFilter = jsonView.Filter; var columns = model.Columns; int count = 0; for (int i = 0; i < columns.Count; i++) { var column = columns[i]; if (!jsonWriter.IsSerializable(column)) { continue; } if (column.Kind == ColumnKind.ColumnListItem) { continue; } if (jsonFilter != null && !jsonFilter.ShouldSerialize(column)) { continue; } if (count > 0) { jsonWriter.WriteComma(); } jsonWriter.WritePropertyName(column.Name); jsonWriter.Write(dataRow, column); count++; } var columnLists = model.ColumnLists; for (int i = 0; i < columnLists.Count; i++) { var columnList = columnLists[i]; if (jsonFilter != null && !jsonFilter.ShouldSerialize(columnList)) { continue; } if (count > 0) { jsonWriter.WriteComma(); } jsonWriter.Write(dataRow, columnList, jsonFilter); count++; } var projections = model.Projections; for (int i = 0; i < projections.Count; i++) { var projection = projections[i]; if (jsonFilter == null || jsonFilter.ShouldSerialize(projection)) { if (count > 0) { jsonWriter.WriteComma(); } Debug.Assert(!string.IsNullOrEmpty(projection.Name)); jsonWriter.WritePropertyName(projection.Name); jsonWriter.Write(jsonView, dataRow, projection); count++; } } if (string.IsNullOrEmpty(model.Namespace)) // for child models, make sure it's not projection. { var childDataSets = dataRow.ChildDataSets; for (int i = 0; i < childDataSets.Count; i++) { var dataSet = childDataSets[i]; if (jsonFilter != null && !jsonFilter.ShouldSerialize(dataSet.Model)) { continue; } if (count > 0) { jsonWriter.WriteComma(); } var childJsonView = jsonView.GetChildView(dataSet); jsonWriter.WritePropertyName(dataSet.Model.Name).InternalWrite(childJsonView, dataSet); count++; } } return(jsonWriter.WriteEndObject()); }
internal static JsonWriter Write(this JsonWriter jsonWriter, IJsonView jsonView, DataRow dataRow) { jsonWriter.WriteStartObject(); var jsonFilter = jsonView.Filter; var _ = dataRow.Model; var columns = _.Columns; int count = 0; for (int i = 0; i < columns.Count; i++) { var column = columns[i]; if (!jsonWriter.IsSerializable(column)) { continue; } if (column.Kind == ColumnKind.ColumnListItem || column.Kind == ColumnKind.ProjectionMember) { continue; } if (jsonFilter != null && !jsonFilter.ShouldSerialize(column)) { continue; } if (count > 0) { jsonWriter.WriteComma(); } jsonWriter.WritePropertyName(column.Name); jsonWriter.Write(dataRow, column); count++; } var columnLists = dataRow.Model.ColumnLists; for (int i = 0; i < columnLists.Count; i++) { var columnList = columnLists[i]; if (jsonFilter != null && !jsonFilter.ShouldSerialize(columnList)) { continue; } if (count > 0) { jsonWriter.WriteComma(); } jsonWriter.Write(dataRow, columnList, jsonFilter); count++; } var projections = dataRow.Model.Projections; for (int i = 0; i < projections.Count; i++) { var projection = projections[i]; if (jsonFilter == null || jsonFilter.ShouldSerialize(projection)) { if (count > 0) { jsonWriter.WriteComma(); } jsonWriter.Write(dataRow, projection, jsonFilter); count++; } } var childDataSets = dataRow.ChildDataSets; for (int i = 0; i < childDataSets.Count; i++) { var dataSet = childDataSets[i]; if (jsonFilter != null && !jsonFilter.ShouldSerialize(dataSet.Model)) { continue; } if (count > 0) { jsonWriter.WriteComma(); } var childJsonView = jsonView.GetChildView(dataSet); jsonWriter.WritePropertyName(dataSet.Model.Name).InternalWrite(childJsonView, dataSet); count++; } return(jsonWriter.WriteEndObject()); }