Node.get

Get the value of the node as specified type.

If the specifed type does not match type in the node, conversion is attempted. The stringConversion template parameter can be used to disable conversion from non-string types to strings.

Numeric values are range checked, throwing if out of range of requested type.

Timestamps are stored as std.datetime.SysTime. Binary values are decoded and stored as ubyte[].

To get a null value, use get!YAMLNull . This is to prevent getting null values for types such as strings or classes.


Mapping default values:

$(PBR The '=' key can be used to denote the default value of a mapping. This can be used when a node is scalar in early versions of a program, but is replaced by a mapping later. Even if the node is a mapping, the get method can be used as if it was a scalar if it has a default value. This way, new YAML files where the node is a mapping can still be read by old versions of the program, which expect the node to be a scalar. )

  1. T get [@property getter]
  2. T get [@property getter]
    struct Node
    @property const @trusted
    T
    get
    (
    T
    Flag!"stringConversion" stringConversion = Yes.stringConversion
    )
    ()
    if (
    is(T == const)
    )

Return Value

Type: T

Value of the node as specified type.

Throws

NodeException if unable to convert to specified type, or if the value is out of range of requested type.

Examples

Automatic type conversion:

auto node = Node(42);

assert(node.as!int == 42);
assert(node.as!string == "42");
assert(node.as!double == 42.0);

Meta