コード例 #1
0
        public void Export <T>(T dataToExport, string outputFile)
        {
            var stream       = streamFactory.createFileStream(outputFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);
            var streamWriter = new StreamWriter(stream);

            using (streamWriter)
            {
                var serializer = Newtonsoft.Json.JsonSerializer.Create();
                serializer.Serialize(streamWriter, dataToExport);
                streamWriter.Flush();
            }
        }
コード例 #2
0
        private void ProcessOutputSingleFile <T>(string fileName, IList <T> result) where T : IOutputJson
        {
            var fs = streamFactory.createFileStream(fileName, FileMode.Create, FileAccess.Write);
            var sw = new StreamWriter(fs);

            var jsonSerializer = JsonSerializer.Create();

            jsonSerializer.Converters.Add(new JsonDateTimeCustomConverter(DailyCodeChurn.DATE_FORMAT, CultureInfo.InvariantCulture));
            using (sw)
            {
                logger.LogToConsole("Writing json to " + fileName);

                var output = new JsonOutputData <T>
                {
                    SchemaVersion = JsonOutputData <T> .CurrentVersion,
                    Data          = result
                };

                jsonSerializer.Serialize(sw, output);
                sw.Flush();
            }
        }