IniFileNet 0.2.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package IniFileNet --version 0.2.0
NuGet\Install-Package IniFileNet -Version 0.2.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.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IniFileNet --version 0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: IniFileNet, 0.2.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.2.0 // Install IniFileNet as a Cake Tool #tool nuget:?package=IniFileNet&version=0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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))))
{
IniValueAcceptorOnlyLast url = new();
IniValueAcceptorOnlyLast outputTemplate = new();
IniValueAcceptorOnlyLast<bool> ask = new(Parse.Boolean);
IniValueAcceptorOnlyLast<Regex?> regex = new((string value) =>
{
try
{
return new(new Regex(value), default);
}
catch (Exception ex)
{
return new(null, new IniError(IniErrorCode.ValueInvalid, string.Concat("Could not parse \"", value, "\" as Regex: ", ex.Message)));
}
});
IniValueAcceptorOnlyLast<DateTimeOffset> latest = new((string value) => DateTimeOffset.TryParse(value, out var r)
? new(r, default)
: new(default, new(IniErrorCode.ValueInvalid, string.Concat("Could not parse \"", value, "\" as datetime"))));
IniValueAcceptorMany<int, HashSet<int>> seen = new(Parse.Int32);
IReadOnlyDictionary<string, IIniValueAcceptor> acceptors = new Dictionary<string, IIniValueAcceptor>()
{
["Url"] = url,
["OutputTemplate"] = outputTemplate,
["Ask"] = ask,
["Regex"] = regex,
["Latest"] = latest,
["Seen"] = seen,
};
while (iniIn.TryReadNext(out var section))
{
IniError err = section.AcceptAll(acceptors);
if (err.Code != default)
{
Console.WriteLine("Error reading ini file: " + err.Msg);
throw err.ToException();
}
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);
}
if (iniIn.Reader.Error.Code != default)
{
Console.WriteLine("Error reading ini file: " + iniIn.Reader.Error.Msg);
throw iniIn.Reader.Error.ToException();
}
}
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. |
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.
- Added some more documentation
- Added convenience class for making IniValueAcceptors
- Added the documentation actually being added to the nuget package file (whoops)