public void Write(object obj, JsonWriterArgs args) { if (obj == null) { args.WriterContainer.GetNullWriter().Write(null, args); return; } var writer = TypeService.IsImmutable <T>() ? args.WriterContainer.GetWriter <T>() : null; var list = (IList <T>)obj; if (list.Count == 0) { args.BeginArray(); args.EndArray(); return; } args.BeginArray(); args.WriteCheckLoop(list[0], writer); for (int i = 1, length = list.Count; i < length; i++) { args.Common(); args.WriteCheckLoop(list[i], writer); } args.EndArray(); }
public void Write(object obj, JsonWriterArgs args) { if (obj == null) { args.WriterContainer.GetNullWriter().Write(null, args); return; } var writer = args.Writer; var list = (IList)obj; if (list.Count == 0) { writer.Write("[]"); return; } args.BeginArray(); args.WriteCheckLoop(list[0], null); for (int i = 1, length = list.Count; i < length; i++) { args.Common(); args.WriteCheckLoop(list[i], null); } args.EndArray(); }
/// <summary> /// </summary> /// <param name="obj"></param> /// <param name="args"></param> /// <exception cref="InvalidOperationException">IDataReader已经关闭</exception> public void Write(object obj, JsonWriterArgs args) { if (obj == null) { args.WriterContainer.GetNullWriter().Write(null, args); return; } var reader = (IDataReader)obj; if (reader.IsClosed) { throw new InvalidOperationException("IDataReader已经关闭"); } args.BeginArray(); if (reader.FieldCount == 1) { var comma = new CommaHelper(args.Writer); while (reader.Read()) { var value = reader.GetValue(0); if (args.IgnoreNullMember) { continue; } if (value == null || value is DBNull) { if (args.IgnoreNullMember) { continue; } args.WriterContainer.GetNullWriter().Write(null, args); } else { args.WriterContainer.GetWriter(value.GetType()).Write(value, args); } comma.AppendCommaIgnoreFirst(); } } else { var writer = args.WriterContainer.GetWriter(Type); if (reader.Read()) { writer.Write(reader, args); while (reader.Read()) { args.Common(); writer.Write(reader, args); } } } args.EndArray(); }
public void Write(object obj, JsonWriterArgs args) { if (obj == null) { args.WriterContainer.GetNullWriter().Write(null, args); return; } var table = (DataTable)obj; var writer = args.Writer; var comma1 = new CommaHelper(writer); var columns = table.Columns; var length = columns.Count; args.BeginArray(); for (int j = 0, count = table.Rows.Count; j < count; j++) { args.BeginObject(); comma1.AppendCommaIgnoreFirst(); var row = table.Rows[j]; var comma = new CommaHelper(writer); for (var i = 0; i < length; i++) { var column = columns[i]; if (args.IgnoreNullMember) { if (row.IsNull(column)) { continue; } } comma.AppendCommaIgnoreFirst(); args.WriterContainer.GetWriter <string>().Write(column.ColumnName, args); writer.Write(':'); if (row.IsNull(column)) { args.WriterContainer.GetNullWriter().Write(null, args); } else { var value = row[column]; args.WriterContainer.GetWriter(value.GetType()).Write(value, args); } } args.EndObject(); } args.EndArray(); }
public void Write(object obj, JsonWriterArgs args) { if (obj == null) { args.WriterContainer.GetNullWriter().Write(null, args); return; } var view = (DataView)obj; var writer = args.Writer; var comma1 = new CommaHelper(writer); var columns = (view.Table ?? view.ToTable()).Columns; var length = columns.Count; args.BeginArray(); for (int j = 0, count = view.Count; j < count; j++) { comma1.AppendCommaIgnoreFirst(); var row = view[j]; var comma = new CommaHelper(writer); for (var i = 0; i < length; i++) { var column = columns[i]; var value = row[i]; if (args.IgnoreNullMember) { if (value == null || value is DBNull) { continue; } } comma.AppendCommaIgnoreFirst(); args.WriterContainer.GetWriter <string>().Write(column.ColumnName, args); writer.Write(':'); if (value == null || value is DBNull) { args.WriterContainer.GetNullWriter().Write(null, args); } else { args.WriterContainer.GetWriter(value.GetType()).Write(value, args); } } } args.EndArray(); }
public void Write(object obj, JsonWriterArgs args) { if (obj == null) { args.WriterContainer.GetNullWriter().Write(null, args); return; } var writer = args.Writer; args.BeginArray(); var ee = (IEnumerator)obj; if (ee.MoveNext()) { args.WriteCheckLoop(ee.Current, null); while (ee.MoveNext()) { args.Common(); args.WriteCheckLoop(ee.Current, null); } } args.EndArray(); }
public void Write(object obj, JsonWriterArgs args) { if (obj == null) { args.WriterContainer.GetNullWriter().Write(null, args); return; } var wirter = TypeService.IsImmutable <T>() ? args.WriterContainer.GetWriter <T>() : null; args.BeginArray(); var ee = ((IEnumerable <T>)obj).GetEnumerator(); if (ee.MoveNext()) { args.WriteCheckLoop(ee.Current, wirter); while (ee.MoveNext()) { args.Common(); args.WriteCheckLoop(ee.Current, wirter); } } args.EndArray(); }