Bodu.Text.DotEnv.Document Namespace
- Package
-
Bodu.Text.DotEnv 1.0.0
Purpose
Bodu.Text.DotEnv.Document is the read-only document object model of Bodu.Text.DotEnv, shaped after System.Text.Json's JsonDocument / JsonElement. A parse produces a disposable DotEnvDocument whose root is the flat object of entries; each DotEnvElement is a lightweight struct cursor over the root or a single string value. Prefer it over the mutable Bodu.Text.DotEnv.Nodes tier when you only need to look values up.
Key types
- DotEnvDocument - the disposable owner:
Parse(fromstringor UTF-8 bytes, with an optional DotEnvReaderOptions) andRootElement. - DotEnvElement - the cursor:
ValueKind(a DotEnvValueKind),GetString,GetProperty/TryGetProperty, andEnumerateObject. - DotEnvElement.ObjectEnumerator - the struct enumerator returned by
EnumerateObject. - DotEnvProperty - a
Name/Valuepair yielded byEnumerateObject.
Example
using Bodu.Text.DotEnv.Document;
using DotEnvDocument env = DotEnvDocument.Parse("export APP_ENV=production\nAPP_PORT=8080\n"u8);
string appEnv = env.RootElement.GetProperty("APP_ENV").GetString();
if (env.RootElement.TryGetProperty("APP_PORT", out DotEnvElement port))
Console.WriteLine(port.GetString());
Notes
- Lifetime. Elements are only valid while their document is undisposed.
- Export flag not surfaced. The read-only model exposes names and values only; use the DotEnvObject DOM or the reader's
CurrentIsExportwhen the prefix matters. - Literal values. No
${VAR}interpolation is applied. - See also: the line-formats introduction and the DotEnv guide (Pattern 1 - query a document).
Classes
- DotEnvDocument
Provides a read-only, forward-parsed view over a DotEnv document, shaped after
System.Text.Json'sJsonDocument. The document is a flat object of string-valued keys; comment trivia is not retained.
Structs
- DotEnvElement
Represents a single element - the root object or one of its string values - within a DotEnvDocument, shaped after
System.Text.Json'sJsonElement.
- DotEnvElement.ObjectEnumerator
Enumerates the properties of a DotEnvElement object.
- DotEnvProperty
Represents a single name/value property of a DotEnvElement object.