Table of Contents

ScalarOptions Class

Definition

Namespace
Codebelt.Extensions.YamlDotNet
Assemblies
Codebelt.Extensions.YamlDotNet.dll
Source
src/Codebelt.Extensions.YamlDotNet/ScalarOptions.cs

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

Name Description
ScalarOptions()

Initializes a new instance of the ScalarOptions class.

Properties

Name Description
IsKey

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

IsPlainImplicit

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

IsQuotedImplicit

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

Style

Gets or sets the style of the scalar.

See Also