IniHelperTool 1.0.0

dotnet add package IniHelperTool --version 1.0.0
                    
NuGet\Install-Package IniHelperTool -Version 1.0.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="IniHelperTool" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IniHelperTool" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="IniHelperTool" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IniHelperTool --version 1.0.0
                    
#r "nuget: IniHelperTool, 1.0.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.
#:package IniHelperTool@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IniHelperTool&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=IniHelperTool&version=1.0.0
                    
Install as a Cake Tool

IniHelper

IniHelper is a .NET library designed to simplify working with INI configuration files. It provides an easy-to-use API for reading and writing INI files, with support for caching, synchronization, and error handling. This tool is designed for developers looking for a robust solution for managing configuration in INI format, with features like backup, async methods, and safe read functionality.

Features

  • Read and Write INI Files: Supports reading and writing data to INI files with custom class attributes.
  • Asynchronous Support: Includes async methods for non-blocking IO operations.
  • Backup and Restore: Automatically creates a backup of the INI file before writing and provides a restore functionality.
  • Thread-Safe: Uses semaphores to handle concurrent read/write operations, ensuring thread safety.
  • Safe Reading: Provides a safe read mode that returns default values when the INI file is corrupted or missing.
  • Performance Testing: Includes built-in performance tests to evaluate parsing time for small, medium, and large INI files.

Installation

To use IniHelper in your project, you can add it as a NuGet package:

dotnet add package IniHelper

Usage

Basic Usage

You can annotate your classes with the provided IniClass and Ini attributes to map class fields and properties to INI file sections and keys.

Example:

[IniClass("AppSettings")]
public class AppConfig
{
    [Ini("Setting1")]
    public string Setting1 { get; set; }

    [Ini("Setting2")]
    public int Setting2 { get; set; }
}

Reading from INI File

To read data from an INI file, use the ReadAsync method. The data will be mapped to your annotated class.

var settings = await IniSettings.CreateAsync("path_to_file.ini");
var config = await settings.ReadAsync<AppConfig>();

Writing to INI File

You can write data to an INI file by passing an instance of your annotated class to the WriteAsync method.

var config = new AppConfig { Setting1 = "Value", Setting2 = 123 };
await settings.WriteAsync(config);

Safe Reading

If you want to safely read an INI file and avoid exceptions in case the file is missing or corrupted, you can use the ReadSafeAsync method. It will return default values if the file is not available or if the cache is empty.

var config = await settings.ReadSafeAsync<AppConfig>();

Restore from Backup

You can restore the INI file from its automatically created backup:

settings.RestoreFromBackup();

Restore from Backup

IniHelper includes tests to measure the performance of reading INI files of various sizes.

To run the performance tests, use the provided test methods in the IniPerformanceTests class. These tests verify that the library can handle small, medium, and large INI files within a reasonable time frame.

dotnet test

The tests will parse INI files of varying sizes (100, 1000, and 10,000 entries) and measure the time taken to read them.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you find any bugs or have suggestions for new features.

License

IniHelper is licensed under the MIT License. See the LICENSE file for more details.

Contact

For any questions or support, feel free to reach out by opening an issue on the GitHub repository.

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.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
1.0.0 149 9/13/2024

Initial release