简体   繁体   中英

yamldotnet added 0x0d in desktop application but not in xamarin android

I need help for my code, i will try to generate license file in cross-platform with yamldotnet but output different then desktop, it's removed 0x0D in xamarin android, i need to keep it 0x0D.

Code for generating license:

public void GenerateLicense()
{
    var YamlStream = new YamlStream(
          new YamlDocument(
              new YamlMappingNode(
                  new YamlScalarNode("XXXXXXXXXXXXXLic"), new YamlMappingNode(
                      new YamlScalarNode("CustomerName"), new YamlScalarNode("Yo"),
                      new YamlScalarNode("CustomerEmail"), new YamlScalarNode("yo@yo.yo"),
                      new YamlScalarNode("HardwareID"), new YamlScalarNode("yo"),
                      new YamlScalarNode("Signature"), new YamlScalarNode()
                      )
                  )
              )
      );

    string yaml;
    var buffer = new StringBuilder();
    using (var writer = new StringWriter(buffer))
    {
        YamlStream.Save(writer, false);
        yaml = writer.ToString();
    }

    var checksum = StringToHex(MD5CheckSumStr(yaml));

    var input = new StringReader(yaml);
    YamlStream = new YamlStream();
    YamlStream.Load(input);

    var mapping = (YamlMappingNode)YamlStream.Documents[0].RootNode;
    ((YamlScalarNode)mapping.Children["XXXXXXXXXXXXXLic"]["Signature"]).Value = checksum;

    using (TextWriter writer = File.CreateText("../yo.yaml"))
    {
        YamlStream.Save(writer, false);
    }
}

Click Here it's output preview image left desktop and right xamarin android

I assume it's using the platform-default line ending.

I suspect if you change your last block to:

using (TextWriter writer = File.CreateText("../yo.yaml"))
{
    writer.NewLine = "\r\n";
    YamlStream.Save(writer, false);
}

... that will fix it. You quite possibly want to do the same thing earlier on when you're writing to the StringWriter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM