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

hypens and comments #581

Closed
jkears opened this issue Feb 12, 2021 · 2 comments
Closed

hypens and comments #581

jkears opened this issue Feb 12, 2021 · 2 comments
Labels

Comments

@jkears
Copy link

jkears commented Feb 12, 2021

The YAML I need to produce has a parameter that includes a hypen such as log-level: debug. How do I achieve this with C# class? Is that using JSON name attribute?

Also how can I inject comments for example # log-level configures the log level

@leonard520
Copy link

I have same use case as @jkears . Is it already supported or not? Thanks.

@EdwardCooke
Copy link
Collaborator

Yes, you can use the [YamlMember] attribute to do both of these.

using YamlDotNet.Serialization;

var serializer = new YamlDotNet.Serialization.SerializerBuilder().Build();
Console.WriteLine(serializer.Serialize(new Test() { LogLevel = "info" }));

class Test
{
    [YamlMember(Alias = "log-level", Description = "log-level configures the log level")]
    public string LogLevel { get; set; }
}

Results in this:

# log-level configures the log level
log-level: info

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

No branches or pull requests

3 participants