IniFileNet 0.3.0

dotnet add package IniFileNet --version 0.3.0
NuGet\Install-Package IniFileNet -Version 0.3.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="IniFileNet" Version="0.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IniFileNet --version 0.3.0
#r "nuget: IniFileNet, 0.3.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.
// Install IniFileNet as a Cake Addin
#addin nuget:?package=IniFileNet&version=0.3.0

// Install IniFileNet as a Cake Tool
#tool nuget:?package=IniFileNet&version=0.3.0

IniFileNet

A .NET Library for reading and writing ini files.

Usage

Note that because this package is currently not at 1.0 yet, this may change. Below is some example code. I'll probably add a loader class that can load a file into memory in one chunk, and then allow one to essentially do dictionary lookups on it.

List<Target> targets = [];
using (IniStreamSectionReader iniIn = new(new IniStreamReader(new StreamReader(new FileStream(args[0], FileMode.Open, FileAccess.Read), Encoding.UTF8), new IniReaderOptions(ignoreComments: true))))
{
	IniValueAcceptorDictionaryBuilder b = new(new Dictionary<string, IIniValueAcceptor>(StringComparer.OrdinalIgnoreCase));
	IniValueAcceptorOnlyLast url = b.OnlyLast("Url");
	IniValueAcceptorOnlyFirst outputTemplate = b.OnlyFirst("OutputTemplate");
	IniValueAcceptorSingle<bool> ask = b.Single("Ask", Parse.Boolean);
	IniValueAcceptorOnlyLast<Regex?> regex = b.OnlyLast("Regex", (string value) =>
	{
		try
		{
			return new IniResult<Regex?>(new Regex(value), default);
		}
		catch (Exception ex)
		{
			return new IniResult<Regex?>(null, new IniError(IniErrorCode.ValueInvalid, string.Concat("Could not parse \"", value, "\" as Regex: ", ex.Message)));
		}
	});
	IniValueAcceptorOnlyLast<DateTimeOffset> latest = b.OnlyLast("Seen", (string value) => DateTimeOffset.TryParse(value, out var r)
		? new IniResult<DateTimeOffset>(r, default)
		: new IniResult<DateTimeOffset>(default, new(IniErrorCode.ValueInvalid, string.Concat("Could not parse \"", value, "\" as DateTimeOffset"))));
	IniValueAcceptorMany<int, HashSet<int>> seen = new(Parse.Int32);
	Dictionary<string, IIniValueAcceptor> acceptors = b.Acceptors;
	while (iniIn.NextSection())
	{
		ReadOnlyIniSection section = iniIn.Section;
		IniError err = section.AcceptAll(acceptors);
		// Can explicitly do it this way
		if (err.Code != default)
		{
			Console.WriteLine("Error reading ini file: " + err.Msg);
			throw err.ToException();
		}
		// Or just call this
		err.ThrowIfError();

		targets.Add(new Target
		(
			name: section.Name,
			url: url.Value ?? throw new IniException(IniErrorCode.ValueMissing, "Url is required for " + section.Name),
			outputTemplate: outputTemplate.Value ?? throw new IniException(IniErrorCode.ValueMissing, "OutputTemplate is required for " + section.Name),
			ask: ask.Value,
			regex: regex.Value,
			latest: latest.Value,
			seen: seen.Values
		));
		Util.ResetAll(acceptors.Values);
	}
	iniIn.Reader.Error.ThrowIfError();
}
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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
0.3.0 0 4/28/2024
0.2.1 54 4/23/2024
0.2.0 132 1/9/2024
0.1.0 84 1/7/2024

- Renamed KeyValue to IniKeyValue, and it is now generic so it can accept a List of strings.
- Added IniValue which doesn't hold the key, only the value and comments.
- IniStreamSectionReader has both NextSection and NextSectionAsync now. Consequently its API has changed, since async methods cannot have out parameters.
- IniError indicates that Msg can be null, which is the case for the default value.
- Added IniDictionaryReader which can load an IniStreamReader into a dictionary, keyed by strings.