Afrowave.SharedTools.IO
0.0.1
dotnet add package Afrowave.SharedTools.IO --version 0.0.1
NuGet\Install-Package Afrowave.SharedTools.IO -Version 0.0.1
<PackageReference Include="Afrowave.SharedTools.IO" Version="0.0.1" />
<PackageVersion Include="Afrowave.SharedTools.IO" Version="0.0.1" />
<PackageReference Include="Afrowave.SharedTools.IO" />
paket add Afrowave.SharedTools.IO --version 0.0.1
#r "nuget: Afrowave.SharedTools.IO, 0.0.1"
#:package Afrowave.SharedTools.IO@0.0.1
#addin nuget:?package=Afrowave.SharedTools.IO&version=0.0.1
#tool nuget:?package=Afrowave.SharedTools.IO&version=0.0.1
Afrowave.SharedTools.IO
The Afrowave.SharedTools.IO library provides a unified, high-level API for working with files — including reading, writing, and serializing data in multiple formats such as JSON, XML, CSV, and YAML.
It is fully compatible with .NET Standard 2.1 and designed to provide safe, consistent, and asynchronous file operations for desktop, web, and background applications.
This package complements Afrowave.SharedTools.Models by using the same unified result model:
- Dependency Injection (DI) service:
IFileService/FileService - Static helper:
FileHelper
📦 Contents
Core Components
Models/FileType.cs– Enumeration defining supported file formats (Json,Xml,Csv,Yaml)Services/IFileService.cs– Interface defining all read/write and serialization methodsServices/FileService.cs– Injectable DI service implementing the unified I/O logicStatic/FileHelper.cs– Static mirror ofIFileServicefor quick or script-style access
⚙️ Purpose
Afrowave.SharedTools.IO simplifies file input/output by abstracting common patterns for reading and writing structured data.
It provides a single consistent API for various file formats, async/sync access, and customizable serialization options — all using modern encoding defaults (UTF-8 without BOM).
Use it when you need to:
- Store or load data objects in JSON, XML, CSV, or YAML
- Implement cross-format import/export utilities
- Build CLI, web, or service applications that handle multiple file types
- Write robust, testable file operations with
ResultandResponse<T>wrappers
💡 IFileService (Dependency Injection)
public interface IFileService
{
// Write
Task<Result> WriteTextAsync(string filePath, string content, Encoding? encoding = null);
Task<Result> WriteBytesAsync(string filePath, byte[] data);
Task<Result> StoreObjectToJsonFileAsync<TData, TOptions>(TData obj, string filePath, TOptions options);
Task<Result> StoreObjectToXmlFileAsync<TData, TOptions>(TData obj, string filePath, TOptions options);
Task<Result> StoreObjectToCsvFileAsync<TData, TOptions>(TData obj, string filePath, TOptions options);
Task<Result> StoreObjectToFileAsync<TData, TOptions>(TData obj, string filePath, FileType fileType, TOptions options);
// Read
Task<Response<string>> ReadTextAsync(string filePath, Encoding? encoding = null);
Task<Response<byte[]>> ReadBytesAsync(string filePath);
Task<Response<TData>> ReadObjectFromFileAsync<TData, TOptions>(string filePath, FileType fileType, TOptions options);
Task<Response<TData>> ReadObjectFromJsonFileAsync<TData, TOptions>(string filePath, TOptions options);
Task<Response<TData>> ReadObjectFromXmlFileAsync<TData, TOptions>(string filePath, TOptions options);
Task<Response<TData>> ReadObjectFromCsvFileAsync<TData, TOptions>(string filePath, TOptions options);
Task<Response<TData>> ReadObjectFromYamlFileAsync<TData, TOptions>(string filePath, TOptions options);
}
All operations are also available synchronously for performance-sensitive or legacy code.
🧠 Example Usage (Dependency Injection)
builder.Services.AddSingleton<IFileService, FileService>();
public class ConfigManager
{
private readonly IFileService _files;
public ConfigManager(IFileService files) => _files = files;
public async Task SaveConfigAsync(MySettings settings)
{
await _files.StoreObjectToJsonFileAsync(settings, "config.json", new JsonSerializerOptions
{
WriteIndented = true
});
}
public async Task<MySettings?> LoadConfigAsync()
{
var response = await _files.ReadObjectFromJsonFileAsync<MySettings, JsonSerializerOptions>("config.json", new());
return response.Success ? response.Data : null;
}
}
⚡ Static Helper Example
The same operations are available without DI using FileHelper, which wraps a singleton instance of FileService.
var data = new Person { Name = "Alice", Age = 30 };
// Store as JSON
var save = FileHelper.StoreObjectToJsonFile(data, "person.json", new JsonSerializerOptions { WriteIndented = true });
// Read as object
var load = FileHelper.ReadObjectFromJsonFile<Person, JsonSerializerOptions>("person.json", new());
if (load.Success)
Console.WriteLine($"Loaded {load.Data.Name}, {load.Data.Age}");
This static pattern is ideal for scripts, console tools, or one-off utilities.
🧩 Supported Formats
| Format | Read / Write | Default Options |
|---|---|---|
| JSON | ✅ / ✅ | camelCase, Indented, IgnoreNullValues |
| XML | ✅ / ✅ | Indented output, UTF-8 (no BOM) |
| CSV | ✅ / ✅ | Comma delimiter, header record, Invariant culture |
| YAML | ✅ / ✅ | CamelCase naming, omit nulls |
Each format accepts native serializer options, e.g.:
JsonSerializerOptionsfor JSONXmlWriterSettingsorXmlReaderSettingsfor XMLCsvConfigurationfor CSVISerializer/IDeserializerfor YAML
🚀 Key Features
| Feature | Description |
|---|---|
| Multi-format serialization | JSON, XML, CSV, and YAML out of the box |
| Async & sync support | All read/write methods available in both forms |
| Unified result model | Uses Result and Response<T> from SharedTools.Models |
| Automatic directory creation | Ensures output directories exist before writing |
| Encoding control | Default UTF-8 (no BOM), optional override |
| Type-safe generic API | Uses generics for strong typing and flexibility |
| Dependency-free design | Minimal dependencies, lightweight for embedded or CLI tools |
🧱 Design Principles
- Clear separation between DI and Static usage
- Full async/await support for scalability
- Safe defaults and unified error handling
- Supports object and raw file operations
- Follows Afrowave naming and modular conventions
📦 Version 0.0.1 Release Notes
| Version | Changes |
|---|---|
| 0.0.1 | Initial release of Afrowave.SharedTools.IO. |
Includes:
• IFileService / FileService (DI)<br>
• FileHelper (static)<br>
• Unified async/sync API for JSON, XML, CSV, and YAML<br>
• Integrated result model (Result, Response<T>) |
✍️ This file is part of the multilingual documentation system.
Translations will be automatically handled by LangHub.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | 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.1
- Afrowave.SharedTools.Models (>= 0.0.31)
- CsvHelper (>= 30.0.1)
- YamlDotNet (>= 15.1.6)
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.0.1 | 225 | 11/4/2025 |