var.init if the path is invalid or missing.var.path
var path(const string[] pathParts) const @safeAccess a nested value using an array of path components.
This method traverses nested objects using the provided path components, returning the value at the final location or var.init if any part of the path is missing or invalid.
Parameters
pathParts | Array of string keys representing the path to traverse. |
Returns
The value at the specified path, or
Examples
var config;
config["database"]["host"] = "localhost";
config["database"]["port"] = 5432;
assert(config.path(["database", "host"]).as!string == "localhost");
assert(config.path(["database", "port"]).as!int == 5432);
assert(config.path(["database", "missing"]).isNull);
assert(config.path(["nonexistent", "deep"]).isNull);var path(const string pathStr) const @safeAccess a nested value using dot-notation or slash-notation path string.
This method parses the path string using '.' or '/' as separators and traverses nested objects accordingly.
Parameters
pathStr | A string path using '.' or '/' as separator (e.g., "a.b.c" or "a/b/c"). |
Returns
The value at the specified path, or
var.init if the path is invalid or missing.Examples
var config;
config["server"]["database"]["host"] = "localhost";
assert(config.path("server.database.host").as!string == "localhost");
assert(config.path("server/database/host").as!string == "localhost");
assert(config.path("server.missing.key").isNull);