Bodu.Text.DotEnv Namespace
- Package
-
Bodu.Text.DotEnv 1.0.0
Purpose
Bodu.Text.DotEnv parses and emits .env files - a flat object of KEY=value entries with export prefixes, quoting, and comments - as a standalone System.Text.Json-shaped library: a typed settings serializer, a forward-only UTF-8 token reader/writer pair, a mutable node DOM, and a read-only document DOM. Values are deliberately literal: no ${VAR} interpolation happens at parse time. It ships as its own package (also available through the Bodu.Text.Formats umbrella); see also Bodu.Text.Delimited and Bodu.Text.Ini.
Key types
- DotEnvSerializer - static serializer: settings classes / dictionaries ↔ DotEnv text.
- DotEnvSerializerOptions / DotEnvSerializerDefaults - naming policy and presets (
Web= SCREAMING_SNAKE_CASE, case-insensitive). - Utf8DotEnvReader / Utf8DotEnvWriter - forward-only
ref structtoken surfaces (export detection, quoting, inline comments). - DotEnvDocument / DotEnvElement - read-only, disposable document model.
- DotEnvNode - mutable DOM root; preserves each entry's
exportflag. - DotEnvFormatException / DotEnvSerializationException - malformed input vs. binding failures.
Example
using Bodu.Text.DotEnv;
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();
Notes
- Literal values. What the file says is what your process gets; interpolation belongs to a higher layer.
- See also: the line-formats introduction and the DotEnv guide.
Namespaces
Classes
- DotEnvFormatException
Represents an error that occurs when DotEnv data is malformed.
- DotEnvSerializationException
Represents an error that occurs while mapping a .NET object to or from DotEnv with DotEnvSerializer, such as an unsupported root type, a missing required key, or a value that cannot be converted to the target type.
- DotEnvSerializer
Provides methods for serializing .NET objects to DotEnv text and deserializing DotEnv text into .NET objects, shaped after
System.Text.Json'sJsonSerializer.
- DotEnvSerializerOptions
Provides configuration for DotEnvSerializer, controlling property naming, case sensitivity, field inclusion, null handling, and the
exportprefix on the write path.
Enums
- DotEnvSerializerDefaults
Specifies a set of default settings a DotEnvSerializerOptions can be initialized from.
- DotEnvTokenType
Enumerates the token kinds a Utf8DotEnvReader reports as it advances through a DotEnv document.
- DotEnvValueKind
Enumerates the value kinds a DotEnv node or element can represent.