IniFileNet 0.5.0
See the version list below for details.
dotnet add package IniFileNet --version 0.5.0
NuGet\Install-Package IniFileNet -Version 0.5.0
<PackageReference Include="IniFileNet" Version="0.5.0" />
paket add IniFileNet --version 0.5.0
#r "nuget: IniFileNet, 0.5.0"
// Install IniFileNet as a Cake Addin #addin nuget:?package=IniFileNet&version=0.5.0 // Install IniFileNet as a Cake Tool #tool nuget:?package=IniFileNet&version=0.5.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.ValueOrException(),
outputTemplate: outputTemplate.ValueOrException(),
ask: ask.Value,
regex: regex.Value,
latest: latest.Value,
seen: seen.Value
));
IniUtil.ResetAll(acceptors.Values);
}
iniIn.Reader.Error.ThrowIfError();
}
Product | Versions 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. |
-
.NETStandard 2.0
- System.Memory (>= 4.5.5)
-
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.
- IniValueAcceptors accept the section and key, to provide better error messages
- IniValueAcceptors have convenience methods for getting a default value or throwing an exception
- IniStreamReader can be configured to trim section, key, and value content