You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It'd be nice to have something similar to System.Text.Json.JsonDocument to do introspection of the yaml document itself and possibly preserve aspects of the document when existing items are only modified and written back to the same file that was edited.
In theory this would help preserve the scalar styles, sequence styles and comments.
The text was updated successfully, but these errors were encountered:
After some time I was able to successfully figure out how to do this with current implementation but could be simpler:
Console.WriteLine("Enter the path to the YAML file:");varinputPath= Console.ReadLine();// check that path is valid and file existsif(!File.Exists(inputPath)){
Console.WriteLine("File does not exist");return;}// open the file and read the contents as a stringvaryamlContent=await File.ReadAllTextAsync(inputPath);usingvarstringReader=new StringReader(yamlContent);varyamlStream=new YamlStream();try{
yamlStream.Load(stringReader);}finally{
stringReader.Close();}varyamlDocument= yamlStream.Documents[0];varrootNode=(YamlMappingNode)yamlDocument.RootNode;varyamlObject= rootNode.Children;
Console.WriteLine("YAML file loaded successfully");// modify the yamlDocument to set the workflow name property to TEST
yamlObject["name"]="TEST";// After modifying the yamlObject, serialize and write it back to the same input filevarserializer=new SerializerBuilder().WithIndentedSequences().Build();awaitusingvaroutput=new StringWriter();try{
serializer.Serialize(output, rootNode);varmodifiedYamlContent= output.ToString();await File.WriteAllTextAsync(inputPath, modifiedYamlContent);
Console.WriteLine("YAML file modified successfully");}finally{
output.Close();}
It'd be nice to have something similar to
System.Text.Json.JsonDocument
to do introspection of the yaml document itself and possibly preserve aspects of the document when existing items are only modified and written back to the same file that was edited.In theory this would help preserve the scalar styles, sequence styles and comments.
The text was updated successfully, but these errors were encountered: