public static string ToTextAll <TRec>(IEnumerable <TRec> records, ChoJSONRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string jsonPath = null) where TRec : class { using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) using (var parser = new ChoJSONWriter <TRec>(writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch }) { parser.Configuration.JSONPath = jsonPath; parser.Write(records); writer.Flush(); stream.Position = 0; return(reader.ReadToEnd()); } }
internal static string ToText(object rec, ChoJSONRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null) { if (rec is DataTable) { StringBuilder json = new StringBuilder(); using (var w = new ChoJSONWriter(json, configuration)) { w.Write(rec as DataTable); } return(json.ToString()); } else if (rec is IDataReader) { StringBuilder json = new StringBuilder(); using (var w = new ChoJSONWriter(json, configuration)) { w.Write(rec as IDataReader); } return(json.ToString()); } ChoJSONRecordWriter writer = new ChoJSONRecordWriter(rec.GetType(), configuration); writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch; using (var stream = new MemoryStream()) using (var reader = new StreamReader(stream)) using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize)) { writer.WriteTo(sw, new object[] { rec }).Loop(); sw.Flush(); stream.Position = 0; return(reader.ReadToEnd()); } }