Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round Tripping YAML file (preservation of comments).... #534

Closed
DynConcepts opened this issue Sep 30, 2020 · 1 comment
Closed

Round Tripping YAML file (preservation of comments).... #534

DynConcepts opened this issue Sep 30, 2020 · 1 comment

Comments

@DynConcepts
Copy link

Is there any way to accomplish this???

@EdwardCooke
Copy link
Collaborator

If you build a concrete class you can put a YamlMember attribute with a description on it to get that in to the yaml, but any other arbitrary comments in your YAML file, no, there is not. There is no record kept of what the original YAML file was after deserializing it into an object.

An example of using the yaml member attribute to put in comments:

using YamlDotNet.Serialization;

var serializer = new SerializerBuilder().Build();
var t = new Test { Value = 123 };
var yaml = serializer.Serialize(t);
Console.WriteLine(yaml);

public class Test
{
    [YamlMember(Description = "A comment")]
    public int Value { get; set; }
}

Results in:

# A comment
Value: 123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants