0

I'm using the following code to deserialize and serialize my object

var deserializer = new DeserializerBuilder().WithTagMapping("str", typeof(string)).Build();
var baseObject = deserializer.Deserialize<Dictionary<object, object>>(File.ReadAllText(path));
// Do some object modification here
string result = new SerializerBuilder().Build().Serialize(baseObject);

However, after the serialization the line separator (like \r\n, \n) was all removed.

My input yaml content

port: 7890

socks-port: 7891

redir-port: 7892

allow-lan: true

My output yaml content:

port: 7890
socks-port: 7891
redir-port: 7892
allow-lan: true

Is there a way to keep the line separator? or add separator between each object

Hhry
  • 823
  • 1
  • 8
  • 19
  • Can you tell us a little bit about why you need them to be there? – Lasse V. Karlsen May 21 '21 at 11:36
  • Sure. I want them to be there because I want it to be easily read by human since there will be tons of object in the yaml content. – Hhry May 21 '21 at 11:52
  • My comment on [this similar question for go-yaml](https://stackoverflow.com/questions/67621557/how-do-you-marshal-a-line-break-in-go-yaml#comment119525235_67621557) applies hier as well. A quick look at YamlDotNet's API gives the impression that it is not any more possible in YamlDotNot than it is in go-yaml. – flyx May 21 '21 at 16:58

0 Answers0