Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

YamlScalar

OfficeIMO.Yaml

Namespace
OfficeIMO.Yaml
Assembly
OfficeIMO.Yaml
Source revision
0eef6a5756b9 with working tree changes
Modifiers
sealed

A scalar node: plain, quoted or block text. A loaded scalar keeps its source spelling (TRUE, 0x1F, ~) and decodes its value once, on first use. An omitted node (key: with no value) is an empty plain scalar.

Inheritance

Remarks

Setting a value equal to the current one under the document's schema keeps the source text, so setting true on TRUE changes nothing. A different value keeps the scalar's style when that style can represent it, and otherwise takes the most conservative style that does.

Usage

Explore 7 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Constructors

YamlScalar 5 overloads
public YamlScalar(string? value) #

Creates a string scalar, or a null scalar (null) when value is null. The style is chosen when the scalar joins a document: plain when no YAML 1.2 core or YAML 1.1 reader could read the text as anything but a string, otherwise following the quoting its siblings use.

Parameters

value string? required
public YamlScalar(string value, YamlStyle style) #

Creates a string scalar with a requested style. When it joins a document, a style that cannot represent the value at its position gives way to the most conservative one that can. A plain style is kept even when the text reads as another type, so new YamlScalar("on", YamlStyle.Plain) writes on.

Parameters

value string required
style OfficeIMO.Yaml.YamlStyle required

Exceptions

  • ArgumentOutOfRangeException – style is not a scalar style.
public YamlScalar(long value) #

Creates an integer scalar.

Parameters

value long required
public YamlScalar(double value) #

Creates a floating-point scalar spelled so YAML 1.2 and YAML 1.1 readers read the same float (1.0, .inf).

Parameters

value double required
public YamlScalar(bool value) #

Creates a boolean scalar (true or false).

Parameters

value bool required

Methods

SetValue 4 overloads
public YamlScalar SetValue(string? value, YamlStyle style = None) #

Sets a string value, or null with null. The style is kept when it can represent the value at this position; otherwise, or for YamlStyle.None, it is chosen as for a new scalar. An equal value keeps the source text.

Parameters

value string? required
style OfficeIMO.Yaml.YamlStyle = None optional

Returns

YamlScalar This scalar.
public YamlScalar SetValue(long value) #

Sets an integer value, keeping the source text when it already equals it (0x1F for 31).

Parameters

value long required

Returns

YamlScalar This scalar.
public YamlScalar SetValue(double value) #

Sets a floating-point value, keeping the source text when it already equals it.

Parameters

value double required

Returns

YamlScalar This scalar.
public YamlScalar SetValue(bool value) #

Sets a boolean value, keeping the source text when it already equals it (TRUE, or yes under YAML 1.1).

Parameters

value bool required

Returns

YamlScalar This scalar.

Properties

public string RawText { get; } #

Gets the scalar's raw text: for a loaded scalar the content between the quotes with escapes intact, or a block scalar's content lines with their indentation, without the header; for a scalar set by editing, the text saving writes for it, with the same parts removed. Use YamlNode.AsString for the decoded value.

public YamlScalarKind Kind { get; } #

Gets what the scalar resolves to under its document's schema: null, boolean, integer, float, string, timestamp, a merge key or YAML 1.1 value key, or YamlScalarKind.Custom for a tag no schema resolves. Use it to pick the YamlNode.GetValue type without trying each one.