Skip to content
huoshan12345Public

About

ConfKit is a lightweight and extensible .NET library for parsing and generating multiple configuration formats, including INI and UCI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

57 Commits

Folders and files

Repository files navigation

ConfKit LICENSE Build

ConfKit is a lightweight and extensible .NET library for parsing and generating multiple configuration formats, including INI and UCI (OpenWrt Unified Configuration Interface).

It provides a consistent programming model, supports structured configuration access, and enables seamless conversion to JSON for strong typing and serialization.


🧩 Multi-format Support

  • INI configuration parsing and generation
  • UCI (OpenWrt) configuration parsing and generation

πŸ— Structured Configuration Model

  • Hierarchical sections and entries
  • Strongly-typed object model
  • Preserve structure and ordering

πŸ”„ JSON Interoperability

  • Convert configurations to JsonObject
  • Deserialize into custom strongly-typed classes
  • Flexible integration with System.Text.Json

⚑ Developer Friendly

  • Simple and intuitive API
  • Works with netstandard2.0 and modern .NET versions
  • Easy to extend for additional formats (TOML, YAML, etc.)

Packages

Package Target Frameworks NuGet
ConfKit netstandard2.0 net8.0 net9.0 net10.0 net472
Package Details
Package Target Frameworks
ConfKit ConfKit is a lightweight and extensible .NET library for parsing and generating multiple configuration formats, including INI and UCI.

Installation

dotnet add package ConfKit

πŸš€ Usage

INI Support

Parse INI Content

string iniContent = @"
[server.database]
host = localhost
port = 1433";

var config = IniParser.Parse(iniContent);

string host = config.Sections
    .First(s => s.Name == "server")
    .SubSections.First(s => s.Name == "database")
    .Entries.First(e => e.Key == "host").Value;

Create INI Configuration

var config = new IniConfig
{
    Entries =
    [
        new IniEntry("debug", "true"),
    ],
    Sections =
    [
        new IniSection("server")
        {
            SubSections =
            [
                new IniSection("database")
                {
                    Entries =
                    [
                        new IniEntry("host", "localhost"),
                        new IniEntry("port", "1433")
                    ],
                },
            ],
        },
    ],
};

string output = config.ToString();

UCI Support

Parse UCI Configuration

string configContent = @"
package network

config interface 'lan'
    option type 'bridge'
    option ifname 'eth0'
    option proto 'static'
";

var config = UciParser.Parse(configContent);

Console.WriteLine(config.PackageName);

Create UCI Configuration

var config = new UciConfig
{
    PackageName = "network",
    Sections =
    [
        new UciSection("interface", "lan")
        {
            Options =
            [
                new UciOption("type", "bridge"),
                new UciOption("ifname", "eth0"),
                new UciOption("proto", "static")
            ]
        }
    ]
};

string output = config.ToString();

πŸ”„ JSON Conversion & Strong Typing

Both INI and UCI configurations can be converted into a JsonObject, making it easy to deserialize into custom types.

Example

var config = IniParser.Parse(iniContent);

// Convert to JSON object
JsonObject json = config.ToSerializableJsonObject();

// Deserialize to custom type
var options = new JsonSerializerOptions
{
    NumberHandling = JsonNumberHandling.AllowReadingFromString
};

var result = json.Deserialize<MyConfig>(options);

TODO

  • Add support for reading and writing comments (current parser just ignores comments)

License

MIT License

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

About

ConfKit is a lightweight and extensible .NET library for parsing and generating multiple configuration formats, including INI and UCI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages