Table of Contents

Class ScalarOptions

Namespace
Codebelt.Extensions.YamlDotNet
Assembly
Codebelt.Extensions.YamlDotNet.dll

Configuration options for EmitterExtensions.

public class ScalarOptions : NodeOptions, IParameterObject
Inheritance
ScalarOptions
Implements
Inherited Members

Examples

The following example demonstrates how to use ScalarOptions to control scalar value formatting (style, quoting) when writing YAML output.

using System;
using System.IO;
using Codebelt.Extensions.YamlDotNet;
using YamlDotNet.Core;
using YamlDotNet.Serialization;

namespace ExampleNamespace;

class Program
{
    static void Main()
    {
        var stringWriter = new StringWriter();
        var emitter = new Emitter(stringWriter);
        
        // Create scalar options for different formatting styles
        var literalStyle = new ScalarOptions
        {
            Style = ScalarStyle.Literal,
            IsKey = false
        };
        
        var quotedStyle = new ScalarOptions
        {
            Style = ScalarStyle.DoubleQuoted,
            IsPlainImplicit = false,
            IsKey = false
        };
        
        emitter.WriteStartObject();
        
        // Write value with literal style (preserves newlines and formatting)
        emitter.WritePropertyName("description");
        emitter.WriteValue(
            "This is a multi-line\ndescription that uses\nliteral style",
            o => o.Style = ScalarStyle.Literal
        );
        
        // Write value with quoted style
        emitter.WritePropertyName("code");
        emitter.WriteValue("special!chars@here", o => o.Style = ScalarStyle.DoubleQuoted);
        
        emitter.WriteEndObject();
        
        var yaml = stringWriter.ToString();
        Console.WriteLine(yaml);
    }
}

Constructors

ScalarOptions()

Initializes a new instance of the ScalarOptions class.

public ScalarOptions()

Remarks

The following table shows the initial property values for an instance of ScalarOptions.

PropertyInitial Value
StyleYamlDotNet.Core.ScalarStyle.Any
IsPlainImplicittrue
IsQuotedImplicittrue
IsKeyfalse

Properties

IsKey

Gets or sets a value indicating whether this scalar event is a key

public bool IsKey { get; set; }

Property Value

bool

true if this scalar event is a key; otherwise, false.

IsPlainImplicit

Gets or sets a value indicating whether the tag is optional for the plain style.

public bool IsPlainImplicit { get; set; }

Property Value

bool

true if tag is optional for the plain style; otherwise, false.

IsQuotedImplicit

Gets or sets a value indicating whether the tag is optional for any non-plain style.

public bool IsQuotedImplicit { get; set; }

Property Value

bool

true if tag is optional for any non-plain style; otherwise, false.

Style

Gets or sets the style of the scalar.

public ScalarStyle Style { get; set; }

Property Value

ScalarStyle

The style of the scalar.

See Also