ByteAid.Extensions.Serialization.Abstractions
1.0.0-alpha.8
dotnet add package ByteAid.Extensions.Serialization.Abstractions --version 1.0.0-alpha.8
NuGet\Install-Package ByteAid.Extensions.Serialization.Abstractions -Version 1.0.0-alpha.8
<PackageReference Include="ByteAid.Extensions.Serialization.Abstractions" Version="1.0.0-alpha.8" />
<PackageVersion Include="ByteAid.Extensions.Serialization.Abstractions" Version="1.0.0-alpha.8" />
<PackageReference Include="ByteAid.Extensions.Serialization.Abstractions" />
paket add ByteAid.Extensions.Serialization.Abstractions --version 1.0.0-alpha.8
#r "nuget: ByteAid.Extensions.Serialization.Abstractions, 1.0.0-alpha.8"
#:package ByteAid.Extensions.Serialization.Abstractions@1.0.0-alpha.8
#addin nuget:?package=ByteAid.Extensions.Serialization.Abstractions&version=1.0.0-alpha.8&prerelease
#tool nuget:?package=ByteAid.Extensions.Serialization.Abstractions&version=1.0.0-alpha.8&prerelease
ByteAid.Extensions.Serialization
A flexible, dependency injection-friendly serialization library for .NET that simplifies the process of implementing custom serialization rules for different data formats. Currently supports CSV, TSV, and PSV (pipe-separated values) with configurable headers and separators.
Features
- Strong typing support
- Configurable through dependency injection
- Support for headers and custom column names
- Multiple separator types (comma, tab, pipe)
- Built with nullable reference types
- Support for both .NET Standard 2.1 and .NET 8.0
- Clean separation of abstractions and implementations
Installation
You can install the package via NuGet:
# Core package
dotnet add package ByteAid.Extensions.Serialization
# Abstractions only
dotnet add package ByteAid.Extensions.Serialization.Abstractions
# Separated text (CSV, TSV, PSV) support
dotnet add package ByteAid.Extensions.Serialization.SeparatedText
Quick Start
1. Define your model
public class Person
{
public string Name { get; set; } = default!;
public int Age { get; set; }
public string Email { get; set; } = default!;
}
2. Configure services
services.AddSerialization(builder =>
{
builder.ConfigureSeparatedText<Person>(rules =>
{
rules.HasHeaders();
rules.Property(p => p.Name, 0, "Full Name");
rules.Property(p => p.Age, 1, "Years");
rules.Property(p => p.Email, 2, "Email Address");
}, ValueSeparator.Comma);
});
3. Use the serialization helper
public class PersonService
{
private readonly ISerializationHelper _serializationHelper;
public PersonService(ISerializationHelper serializationHelper)
{
_serializationHelper = serializationHelper;
}
public string SerializePeople(IEnumerable<Person> people)
{
return _serializationHelper.SerializeAsSeparatedText(people);
}
public Person DeserializePerson(string input)
{
return _serializationHelper.DeserializeFromSeparatedText<Person>(input);
}
}
Advanced Usage
Different Separator Types
The library supports three types of separators:
// CSV (Comma-Separated Values)
builder.ConfigureSeparatedText<Person>(rules => { ... }, ValueSeparator.Comma);
// TSV (Tab-Separated Values)
builder.ConfigureSeparatedText<Order>(rules => { ... }, ValueSeparator.Tab);
// PSV (Pipe-Separated Values)
builder.ConfigureSeparatedText<Address>(rules => { ... }, ValueSeparator.Pipe);
Custom Header Names
You can specify custom header names for your properties:
builder.ConfigureSeparatedText<Person>(rules =>
{
rules.HasHeaders();
rules.Property(p => p.Name, 0, "Full Name");
rules.Property(p => p.BirthDate, 1, "Date of Birth");
rules.Property(p => p.Email, 2, "Contact Email");
}, ValueSeparator.Comma);
Working with Headers
You can get header information programmatically:
// Get header line with separator
string headerLine = _serializationHelper.GetHeaderLine<Person>();
// Get headers as array
string[] headers = _serializationHelper.GetHeadersArray<Person>();
Type Support
The library supports a wide range of .NET types for serialization/deserialization:
- Basic types (string, int, long, decimal, etc.)
- DateTime and DateTimeOffset
- TimeSpan
- Guid
- Enums
- Nullable value types
- Boolean (with support for various formats)
- Uri
- Version
- IPAddress
- Base64-encoded byte arrays
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Prerequisites
- .NET SDK 8.0 or later
- An IDE that supports .NET (Visual Studio, VS Code, Rider)
Building the Project
dotnet build
Running Tests
dotnet test
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you encounter any problems or have suggestions, please open an issue on GitHub.
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 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. |
.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
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ByteAid.Extensions.Serialization.Abstractions:
Package | Downloads |
---|---|
ByteAid.Extensions.Serialization
A flexible serialization library for .NET providing configuration-based serialization capabilities with dependency injection support. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0-alpha.8 | 74 | 12/25/2024 |