BroncoSettingsParser 1.0.0
dotnet add package BroncoSettingsParser --version 1.0.0
NuGet\Install-Package BroncoSettingsParser -Version 1.0.0
<PackageReference Include="BroncoSettingsParser" Version="1.0.0" />
<PackageVersion Include="BroncoSettingsParser" Version="1.0.0" />
<PackageReference Include="BroncoSettingsParser" />
paket add BroncoSettingsParser --version 1.0.0
#r "nuget: BroncoSettingsParser, 1.0.0"
#:package BroncoSettingsParser@1.0.0
#addin nuget:?package=BroncoSettingsParser&version=1.0.0
#tool nuget:?package=BroncoSettingsParser&version=1.0.0
Bronco Settings Parser
A self-documenting settings parser that reads .bronco
files and returns values to your program.
Install
Broco Settings Parser requires .NET 8.0.
// Can't do that yet...
Table of contents
- Load a configuration file
- Bronco file specifications
- Limitations
- Read a bronco file
- Mapping
- Validation
- Using Bronco for serializable user settings
- Examples
Load a configuration file
This code loads settings from a string constant:
using BroncoSettingsParser;
const string settings = @"
<<<Begin:Setting:BackgroundColor>>>
#DDDDDD
<<<End:Setting>>>
<<<Begin:Setting:ForegroundColor>>>
#220022
<<<End:Setting>>>
";
var parser = new Parser(settings);
var response = parser.Parse();
Console.WriteLine(response.Settings.GetValue("BackgroundColor")); // #DDDDDD
Console.WriteLine(response.Settings.GetValue("ForegroundColor")); // #220022
This code loads settings from a .bronco
file called mysettings.bronco
, located in the same folder as the running exe-file.
The contents of the file is the same as the contents of the string constant in the previous example.
var parser = new Parser(new FileInfo(Path.Combine(Tools.ExeFolder.FullName, "mysettings.bronco")));
var response = parser.Parse();
Console.WriteLine(response.Settings.GetValue("BackgroundColor")); // #DDDDDD
Console.WriteLine(response.Settings.GetValue("ForegroundColor")); // #220022
The only supported datatype is string. Constrains can be implemented using other libraries.
Bronco file specifications
A Bronco settings file is any UTF-8 encoded text file with .bronco
as file ending. Bronco settings files are not case sensitive.
The file consists of any number of Setting
sections. A setting opens with a row that contains the words Begin, Setting, and a name.
A name starts with a letter and consist of letters and numbers. No other characters are allowed in the name.
A setting closes with <<<End:Setting>>>
. Whitespaces are trimmed away, but the opening row and closing row cannot have any
other text in them. This is ok:
<<<Begin:Setting:Name goes here>>>
<<<End:Setting>>>
This is not ok:
Open a block: <<<Begin:Setting:Name goes here>>>
<<<End:Setting>>>
Whitespaces in names are not preserved. Whitespaces before and after the name will be removed, any whitespaces within the name (spaces or tabs) will be replaced with one space.
More information is available here.
Limitations
- Escape sequences are not supported. Therefore a a name or a value of a setting cannot contain
<<<
,>>>
,/*
or*/
. - Opening tags (
<<<Begin:Setting:Example setting>>>
) and closing tags (<<<End:Setting>>>
) must stand alone on a row in the settings file. - The only supported datatype is
string
, but custom value parsers can be provided when mapping is used.
Read a bronco file
This is the sample file:
<<<Begin:Setting:Setting 1>>>
/* The first setting */
I am value!
<<<End:Setting>>>
<<<Begin:Setting:The Second Setting>>>
/* The 2:nd setting */
I am also
value.
<<<End:Setting>>>
This code iterates through the two settings:
using BroncoSettingsParser;
var parser = new Parser(new FileInfo(Path.Combine(Tools.ExeFolder.FullName, "samplefile.bronco")));
var response = parser.Parse();
for (var i = 0; i < response.Settings.Count; i++)
Console.WriteLine($"Setting {i + 1}: {response.Settings[i].Value}");
This is the result:
Setting 1: I am value!
Setting 2: I am also value!
To read a specific setting, call the GetValue
method:
using BroncoSettingsParser;
var parser = new Parser(new FileInfo(Path.Combine(Tools.ExeFolder.FullName, "samplefile.bronco")));
var response = parser.Parse();
Console.WriteLine(response.Settings.GetValue("The Second Setting"));
The result is I am also value!
.
Mapping
Mapping requires the least code to acquire settings from a .bronco
file.
All settings need to be named accordingly to C# name rules.
<<<Begin:Setting:Setting1>>>
/* The first setting */
I am value!
<<<End:Setting>>>
<<<Begin:Setting:TheSecondSetting>>>
/* The 2:nd setting */
I am also
value.
<<<End:Setting>>>
Class to map the settings to:
public class MyNiceSettings
{
public string Setting1 { get; set; }
public string TheSecondSetting { get; set; }
public MyNiceSettings() : this("", "")
{
}
public MyNiceSettings(string setting1, string theSecondSetting)
{
Setting1 = setting1;
TheSecondSetting = theSecondSetting;
}
}
Read the settings:
using BroncoSettingsParser;
using BroncoSettingsParser.ResponseModel;
var parser = new Parser(new FileInfo(Path.Combine(Tools.ExeFolder.FullName, "mapping.bronco")));
var response = parser.Parse();
if (response.Status != Status.Success)
throw new SystemException("Parse failed.");
var settings = response.Map<MyNiceSettings>();
Console.WriteLine(settings.Setting1);
Console.WriteLine(settings.TheSecondSetting);
If not all names are matched, an exception will occur.
More information and datatype support is available here.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. |
-
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 | 215 | 4/13/2025 |