LtxConfigModel 1.0.0

dotnet add package LtxConfigModel --version 1.0.0
                    
NuGet\Install-Package LtxConfigModel -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LtxConfigModel" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LtxConfigModel" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="LtxConfigModel" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LtxConfigModel --version 1.0.0
                    
#r "nuget: LtxConfigModel, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LtxConfigModel@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LtxConfigModel&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=LtxConfigModel&version=1.0.0
                    
Install as a Cake Tool

LtxConfigModel

A small .NET library for parsing, representing and serializing .ltx configuration files used by the S.T.A.L.K.E.R. series.

Features

  • Parse .ltx text into a document model composed of sections and lines
  • Preserve padding, comments and include directives
  • Modify keys, values and sections programmatically and serialize back to text

Quick Start

Installation

This project targets .NET 6, .NET 8, and .NET 10. Reference the NuGet package or add the project to your solution.

Basic Usage

using LtxConfigModel;

var content = @"
[general]
fullscreen = true ; enable fullscreen
[render]
texture_detail = 2, 4, 6
";

// Parse
var parser = new LtxParser(content);
var doc = parser.Parse();

// Access sections
var render = doc.FindSection("render");
var keys = render?.GetKeys();
var textureValues = render?.GetValues("texture_detail");

// Modify a value
render?.SetValue("texture_detail", "3");

// Add new section and key
var sec = doc.AddSection("custom");
sec.AddKeyValue("enabled", "1");

// Serialize back to text
var output = doc.Serialize();
Console.WriteLine(output);

Working with Lines and Elements

The model exposes a Line class that contains a sequence of LineElement objects. Elements include:

  • KeyElement — the left-hand key of a key/value line
  • ValueElement — the value block (can contain multiple ValueItem tokens)
  • CommentElement — trailing comment starting with ;
  • IncludeElement — #include "path" directive

You can create lines programmatically using factory helpers:

var line = Line.KeyValue("my_key", "my_value");
var lineWithComment = Line.KeyValueComment("my_key", "my_value", "a note");
var include = Line.Include("configs\\other.ltx");

API Overview

LtxDocument

Represents the entire parsed .ltx file:

  • Root — the root (unnamed) section
  • Sections — all sections in the document
  • AddSection(name) — add a new section
  • FindSection(name) — find a section by name (case-insensitive)
  • Serialize() — convert back to text

LtxSection

Represents a named section [name:parent1, parent2]:

  • Name — section name
  • Lines — list of lines in the section
  • Add(line) — add a line to the section
  • AddKeyValue(key, value) — shortcut to add a key/value pair
  • GetKeys() — return all keys in the section
  • GetValue(key) — get single value for a key
  • GetValues(key) — get all comma-separated values for a key
  • SetValue(key, value) — replace a value
  • SetValues(key, values) — replace multiple values

Line

Represents a single line of configuration:

  • KeyValue(key, value) — factory for key/value lines
  • KeyValueComment(key, value, comment) — factory with trailing comment
  • Include(path) — factory for include directives
  • Comment(text) — factory for comment-only lines
  • Empty() — factory for empty lines
  • Add(element) — add an element to the line
  • GetKey() — get the KeyElement if present
  • GetValue() — get the ValueElement if present
  • GetValues() — get value items if present
  • Serialize() — convert back to text

Preserving Formatting

The library tries to preserve padding and comments when parsing and re-serializing. Use Padding values on elements when building lines manually to control spacing exactly.

var padding = new Padding(left: 2, right: 1);  // 2 spaces left, 1 space right
var key = new KeyElement("my_key", padding);

Notes

This library focuses on faithful round-trip parsing and editing of .ltx files rather than interpreting semantics. It preserves whitespace, comments, and include directives, allowing safe programmatic editing of keys, values, and sections.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 133 6/26/2026