YamlReaderOptions struct

Provides the ability for the user to define custom behavior when reading YAML.

Namespace: System.Text.Yaml ยท Assembly: Styml.dll

public struct YamlReaderOptions

Provides the ability for the user to define custom behavior when reading YAML.

PropertiesLink to this heading

AcceptLenientScalarsLink to this heading

Gets or sets whether typed reads accept scalars that YamlDotNet or SharpYaml resolve although no YAML standard does. false by default. When it is set:

  • Utf8YamlReader.GetBoolean accepts true and false in any case (tRue), and with YamlSchemaKind.Yaml11 also y, yes, n, no, on and off in any case (yEs).
  • Utf8YamlReader.GetDouble and Utf8YamlReader.GetSingle accept .inf and .nan in any case, with or without a sign, and .NET's nan and infinity in any case (-Infinity).
  • The boolean and number readers also accept a quoted, block or tagged scalar ('true', "12", !!str 1.5, | blocks) whose text, trimmed of white space and line breaks, is the plain scalar of a boolean, a number or one of those names. A quoted null ('', 'null') is still a string.
  • An enum read takes a quoted, block or tagged number as the plain number ('1'), and the date, time, Guid and Version readers take a quoted or block text padded with white space or line breaks as its trimmed text (' 2001-01-01 '); a Char takes one character followed by white space or a line break.
  • A core tag also takes those forms: !!bool tRuE, !!float .iNf and !!null NuLL resolve to their type, so for these three the token type changes.
  • The serializer reads null in any case (NuLL) as it reads null into a target that is not Object or a YAML document or node type, and reads a null into a non-nullable value type (Int32, Boolean, an enum, a struct) as its default. A constructor parameter is the exception: it refuses a null as without the option, where a property of the same type takes the default.
  • A plain Boolean dictionary key in another case than the core schema's (tRue:) reads only with the option, and with YamlSchemaKind.Yaml11 so does yEs:.
  • Under YamlSchemaKind.Json, an untagged plain scalar that matches no JSON form (yes, True, ~, 0x1F, foo, the empty scalar) is a YamlTokenType.String, as SharpYaml reads it, rather than an error. It is a superset of SharpYaml's reading, since the other rules still apply: True then reads into a Boolean, which SharpYaml's JSON schema refuses; 1_000 and .inf stay strings.

A converter of your own that handles null receives a NuLL scalar as the YamlTokenType.String token it is, not as YamlTokenType.Null. Styml's writer writes a string such as NuLl plain by default, which a lenient reader takes as null; write with YamlWriterOptions.QuoteForLenientReaders to read every string back.

public bool AcceptLenientScalars { get; set; }

AllowMultipleValuesLink to this heading

Defines whether the Utf8YamlReader should tolerate zero or more top-level YAML values that are whitespace separated.

public bool AllowMultipleValues { get; set; }

By default, it's set to false, and is thrown if trailing content is encountered after the first top-level YAML value.

AllowTrailingCommasLink to this heading

Kept for source compatibility with System.Text.Json; it has no effect. YAML flow collections always allow (and ignore) one trailing comma before their closing bracket.

public bool AllowTrailingCommas { get; set; }

The JSON grammar that read this option was deleted in M7a (decision D8); setting it changes nothing.

CommentHandlingLink to this heading

Defines how the Utf8YamlReader handles comments: YAML's # comments, and with YamlCommentHandling.Skip or YamlCommentHandling.Allow the JSON comments (// and /* */) of a JSON payload.

public YamlCommentHandling CommentHandling { get; set; }
Exception Condition
ArgumentOutOfRangeException Thrown when the comment handling enum is set to a value that is not supported (i.e. not within the YamlCommentHandling enum range).

By default (YamlCommentHandling.Disallow) # comments are skipped and // and /* */ are not comments, as in standard YAML. See YamlCommentHandling for where JSON comments are read.

DisallowImplicitCollectionKeysLink to this heading

Gets or sets whether a flow collection may not be an implicit mapping key ([a, b]: v, {a: b}: v, [[a]: b], {[a]: b}). false by default: YAML allows such keys, and deciding whether a [ or { at the root or in a flow sequence starts one needs the rest of its line (at most 1024 characters), so with partial data the reader may wait for more input before it returns YamlTokenType.StartArray or YamlTokenType.StartObject. Set it to true to read such collections at once, as the YAML reader does, for example for a stream of YAML; an implicit collection key is then an error. Explicit keys (? [a, b]) are not affected.

public bool DisallowImplicitCollectionKeys { get; set; }

MaxDepthLink to this heading

Gets or sets the maximum depth allowed when reading YAML, with the default (i.e. 0) indicating a max depth of 64.

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 .

SchemaLink to this heading

Gets or sets the schema that gives plain scalars in value position their token type and that the typed readers (Utf8YamlReader.GetInt32 and the others) accept. YamlSchemaKind.Core, the YAML 1.2 core schema, by default.

public YamlSchemaKind Schema { get; set; }
Exception Condition
ArgumentOutOfRangeException The value is not a defined YamlSchemaKind.

Generated from the XML documentation of the libraryBuilt with Douze

Esc to close