YamlWriterOptions struct
Provides the ability for the user to define custom behavior when writing YAML using the Utf8YamlWriter. By default, the YAML is written without any indentation or extra white space. Also, the Utf8YamlWriter will throw an exception if the user attempts to write structurally invalid YAML.
Namespace: System.Text.Yaml ยท Assembly: Styml.dll
public struct YamlWriterOptions
Provides the ability for the user to define custom behavior when writing YAML using the Utf8YamlWriter. By default, the YAML is written without any indentation or extra white space. Also, the Utf8YamlWriter will throw an exception if the user attempts to write structurally invalid YAML.
PropertiesLink to this heading
DefaultScalarStyleLink to this heading
In block style, the style for every string value that has no style of its own: no Utf8YamlWriter.WriteScalarStyle hint, no member YamlScalarStyleAttribute and no source style kept by a YamlDocument or a YamlNode. YamlScalarStyle.None, the default, leaves the writer's own choice. For a string with a line break, a YamlWriterOptions.MultiLineStringStyle that is set goes first. The style is applied where the string can be written in it, as a hint is; otherwise the string is written as it would be without it: plain cannot hold a line break, a block scalar needs one, single quotes over several lines cannot hold a tab or a space next to a line break, and inside a flow collection a string is never a block scalar. A value the writer writes as a YAML string from its own text (a date, a time, a GUID, Base64) takes a single- or double-quoted default, and keeps its form under the others. A key is styled only when the serializer or the DOM writes a dictionary's or a YamlObject's string key; member names and names written with Utf8YamlWriter.WritePropertyName are not, and a key cannot be a block scalar. Numbers, booleans and nulls are not styled, and a string written in segments stays double-quoted. Ignored in JSON-compatible style.
public YamlScalarStyle DefaultScalarStyle { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is not a scalar style. |
EncoderLink to this heading
The encoder to use when escaping strings, or null to use the default encoder.
public JavaScriptEncoder? Encoder { get; set; }
ExpandSequenceItemsLink to this heading
In block style, whether a collection that is a sequence item starts on the line after its dash (-\n a: 1, -\n - 1) rather than on the dash's line (- a: 1, - - 1, the default). Ignored in JSON-compatible style.
public bool ExpandSequenceItems { get; set; }
IgnoreSourceStylesLink to this heading
In block style, whether a YamlDocument, a YamlElement or a YamlNode is written in this writer's own styles rather than its source's: collections in the writer's style (block), scalars and keys as the writer would choose them for the same text (so a YAML source's quoted keys and strings are written plain where plain is safe), with YamlWriterOptions.DefaultScalarStyle and YamlWriterOptions.MultiLineStringStyle applying as they do to any value. A style set explicitly still applies: Utf8YamlWriter.WriteScalarStyle, Utf8YamlWriter.WriteCollectionStyle, a member's style, and a node's YamlObject.CollectionStyle or YamlArray.CollectionStyle set by the caller. Anchors and tags are content and are written as before. Off by default: written back, a document keeps its source's styles, as YamlDotNet's and SharpYaml's models do. Ignored in JSON-compatible style.
public bool IgnoreSourceStyles { get; set; }
IndentCharacterLink to this heading
Defines the indentation character used by Utf8YamlWriter when YamlWriterOptions.Indented is enabled. Defaults to the space character.
public char IndentCharacter { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | value contains an invalid character. |
Allowed characters are space and horizontal tab.
IndentSequencesLink to this heading
In block style, whether a sequence under a key is indented (key:\n - a) rather than written at the key's column (key:\n- a, the default). Ignored in JSON-compatible style.
public bool IndentSequences { get; set; }
IndentSizeLink to this heading
Defines the indentation size used by Utf8YamlWriter when YamlWriterOptions.Indented is enabled. Defaults to two.
public int IndentSize { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | value is out of the allowed range. |
Allowed values are integers between 0 and 127, included.
IndentedLink to this heading
Defines whether the Utf8YamlWriter should pretty print the YAML which includes: indenting nested YAML tokens, adding new lines, and adding white space between property names and values. By default, the YAML is written without any extra white space.
public bool Indented { get; set; }
MaxDepthLink to this heading
Gets or sets the maximum depth allowed when writing YAML, with the default (i.e. 0) indicating a max depth of 1000.
public int MaxDepth { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when the max depth is set to a negative value. |
Reading past this depth will throw a .
MaxLineWidthLink to this heading
In block style, the width past which plain, double-quoted and folded scalars are folded onto the next line, at a space; 0 (the default) means no folding. A line can still be longer, when it has no space to fold at. Keys and scalars inside flow collections are not folded; instead a flow collection starts a new line before its next item or key once a line is past the width (after the comma, as libyaml's emitter does), indented one level per open flow collection past the enclosing block level. The column is kept across flushes. Ignored in JSON-compatible style.
public int MaxLineWidth { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is negative. |
MultiLineStringStyleLink to this heading
In block style, how a string value with a line break is written when no style hint applies to it: YamlScalarStyle.Literal (|, also what YamlScalarStyle.None, the default, means), YamlScalarStyle.Folded (>) or YamlScalarStyle.DoubleQuoted ("a\nb", the default before M5f). A string that a block scalar cannot hold is double-quoted whatever this says: a \r, a control character, NEL, LS or PS, a line made only of spaces, no character but line breaks, a first line that starts with a tab, or, at the root, a first line that starts with a space. Keys, strings in a flow collection and strings written in segments are never block scalars. Ignored in JSON-compatible style.
public YamlScalarStyle MultiLineStringStyle { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | The value is YamlScalarStyle.Plain, YamlScalarStyle.SingleQuoted or not a scalar style. |
NewLineLink to this heading
Gets or sets the new line string to use when YamlWriterOptions.Indented is true. The default is the value of Environment.NewLine.
public string NewLine { get; set; }
| Exception | Condition |
|---|---|
| ArgumentNullException | Thrown when the new line string is null. |
| ArgumentOutOfRangeException | Thrown when the new line string is not \n or \r\n. |
QuoteForLenientReadersLink to this heading
In block style, also quotes the strings that some readers read as something other than a string although neither YAML 1.2 nor YAML 1.1 resolves them: keywords in a case no standard lists (tRuE, yEs), the IEEE names (nan, Infinity), number forms with underscores or white space where no standard accepts them (_1, -0o17), Unicode white space at an edge, keys with * after a space, ? and : in plain scalars inside flow collections, literal scalars with a line that starts with a tab (written double-quoted), and the four kinds of form Ruby's Psych 3.1 reads as a number, a date or a time, or fails on, where neither standard does: sexagesimal numbers with a leading zero such as 09:30, digits with commas such as 1,000, dates and timestamps by Psych's own patterns (a one-digit month or day such as 2024-3-1, a leading - such as -2001-12-14 21:59:43, a zone such as +0500), and a float with no digit before the exponent such as .e+0. The readers it was checked against are YamlDotNet, SharpYaml, VYaml, Psych 3.1 and PyYAML 6. Off by default: the default output is standard YAML that every conforming reader reads back as written; this option accommodates the readers that do not. Ignored in JSON-compatible style.
public bool QuoteForLenientReaders { get; set; }
SkipValidationLink to this heading
Defines whether the Utf8YamlWriter should skip structural validation and allow the user to write invalid YAML, when set to true. If set to false, any attempts to write invalid YAML will result in a to be thrown.
public bool SkipValidation { get; set; }
If the YAML being written is known to be correct, then skipping validation (by setting it to true) could improve performance. An example of invalid YAML where the writer will throw (when SkipValidation is set to false) is when you write a value within a YAML object without a property name.
StyleLink to this heading
The output style: YamlWriterStyle.Block YAML, or YamlWriterStyle.JsonCompatible JSON. When it is not set, the writer writes block YAML.
public YamlWriterStyle Style { get; set; }
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | value is not a defined style. |