IniFileNet 0.6.0

dotnet add package IniFileNet --version 0.6.0                
NuGet\Install-Package IniFileNet -Version 0.6.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.6.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IniFileNet --version 0.6.0                
#r "nuget: IniFileNet, 0.6.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.6.0

// Install IniFileNet as a Cake Tool
#tool nuget:?package=IniFileNet&version=0.6.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.

The IniStreamReader class lets you read individual sections, keys and values, and comments. The IniStreamSectionReader wraps that class and groups keys and values up into sections for you.

You can use instances of IIniValueAcceptor to accept values with specific keys from a section, which helps parsing destination types and validating that everything loads correctly.

List<Target> targets = [];
using (IniStreamSectionReader iniIn = new(new IniStreamReader(new StreamReader(new FileStream(args[0], FileMode.Open, FileAccess.Read), Encoding.UTF8), DefaultIniTextEscaper.Default, 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", IniParse.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(IniParse.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.ValueOrException(),
			outputTemplate: outputTemplate.ValueOrException(),
			ask: ask.Value,
			regex: regex.Value,
			latest: latest.Value,
			seen: seen.Value
		));
		IniUtil.ResetAll(acceptors.Values);
	}
	iniIn.Error.ThrowIfError();
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

  • net6.0

    • No dependencies.
  • net7.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
0.6.0 68 10/1/2024
0.5.0 76 6/18/2024
0.4.0 80 5/8/2024
0.3.0 62 4/28/2024
0.2.1 77 4/23/2024
0.2.0 146 1/9/2024
0.1.0 100 1/7/2024

- Support for escape sequences added, both reading and writing
- Trimming strings is supported by IniSpanReader
- Renamed HaveValue to HasValue to be consistent with .NET
- Empty section names are disallowed on parsing