IniFileNet 0.3.0
See the version list below for details.
dotnet add package IniFileNet --version 0.3.0
NuGet\Install-Package IniFileNet -Version 0.3.0
<PackageReference Include="IniFileNet" Version="0.3.0" />
paket add IniFileNet --version 0.3.0
#r "nuget: IniFileNet, 0.3.0"
// 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 | 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. |
-
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.
- 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.