本文整理汇总了C#中JsonSerializer.SerializeToWriter方法的典型用法代码示例。如果您正苦于以下问题:C# JsonSerializer.SerializeToWriter方法的具体用法?C# JsonSerializer.SerializeToWriter怎么用?C# JsonSerializer.SerializeToWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonSerializer
的用法示例。
在下文中一共展示了JsonSerializer.SerializeToWriter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveModel
private void SaveModel(string fileLocation)
{
using (var writer = new StreamWriter(fileLocation))
{
var serializer = new JsonSerializer<MusicModel>();
serializer.SerializeToWriter(_musicViewModel.MusicModel, writer);
}
}
示例2: ServiceStackSerialize
public void ServiceStackSerialize()
{
DatabaseCompat db = GetNorthwindObject();
JsonSerializer<DatabaseCompat> serializer = new JsonSerializer<DatabaseCompat>();
serializer.SerializeToWriter(db, TextWriter.Null);
Time(Iterations, () => serializer.SerializeToWriter(db, TextWriter.Null));
}
示例3: Main
//.........这里部分代码省略.........
try
{
Directory.CreateDirectory(p.Object.DumpDir);
}
catch (Exception ex)
{
_logger.Error($"Error creating DumpDir '{p.Object.DumpDir}': {ex.Message}. Exiting");
return;
}
}
var key = reg.GetKey(p.Object.DumpKey);
if (key == null)
{
_logger.Warn($"Key not found: {p.Object.DumpKey}. Exiting");
return;
}
var nout = $"{key.KeyName}_dump.json";
var fout = Path.Combine(p.Object.DumpDir, nout);
_logger.Info("Found key. Dumping data. Be patient as this can take a while...");
var jsons = new JsonSerializer<RegistryKey>();
//TODO need a way to get a simple representation of things here, like
//name, path, date, etc vs EVERYTHING
using (var sw = new StreamWriter(fout))
{
sw.AutoFlush = true;
jsons.SerializeToWriter(key,sw);
}
_logger.Warn($"'{p.Object.DumpKey}' saved to '{fout}'");
}
else if (p.Object.KeyName.Length > 0)
{
var key = reg.GetKey(p.Object.KeyName);
if (key == null)
{
_logger.Warn($"Key '{p.Object.KeyName}' not found.");
DumpStopWatchInfo();
continue;
}
if (p.Object.ValueName.Length > 0)
{
var val = key.Values.SingleOrDefault(c => c.ValueName == p.Object.ValueName);
if (val == null)
{
_logger.Warn($"Value '{p.Object.ValueName}' not found for key '{p.Object.KeyName}'.");
DumpStopWatchInfo();
continue;
}
_sw.Stop();
totalSeconds += _sw.Elapsed.TotalSeconds;
_logger.Info(val);