CodingCat.Serializers 0.1.0

dotnet add package CodingCat.Serializers --version 0.1.0
                    
NuGet\Install-Package CodingCat.Serializers -Version 0.1.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="CodingCat.Serializers" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodingCat.Serializers" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="CodingCat.Serializers" />
                    
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 CodingCat.Serializers --version 0.1.0
                    
#r "nuget: CodingCat.Serializers, 0.1.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 CodingCat.Serializers@0.1.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=CodingCat.Serializers&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=CodingCat.Serializers&version=0.1.0
                    
Install as a Cake Tool

CodingCat.Serializers

Provides interfaces and serializers to convert between different types

Using the StringSerializer

There are some products accept only the byte[] such as RabbitMq as an input, however, it is quite annoying to convert a concrete type between byte[] no matter using dotnet BinarySerializer or Json.Net to convert an instance to JSON string then to byte[].

CodingCat.Serializers.Impls.StringSerializer is implementing the ISerializer<string> and will be served as the default serializer for the others, thus converting anything to bytes will be more easier.

var serializer = new StringSerializer() // -- default using UTF8 as the encoding
  .WithEncoding(Encoding.UTF7);         // -- no need to use this function if you are happy with UTF8
var input = "TEST_SERIALIZER";
var bytes = serializer.ToBytes(input);
var output = serializer.FromBytes(output);
Using the JsonSerializer

With JsonSerializer, we could easily convert any object to byte[] while its uses Json.Net internally.

var serializer = new JsonSerializer<UserCommand>() // -- uses CodingCat.Serializers.Impls.StringSerializer by default
  .WithSerializer(new MyAwesomeStringSerializer()) // -- the default string serializer is replacable
  .WithSettings(this.jsonSerializerSettings);      // -- could setup the Json.Net setting easily
var userService = new UserService()
  .UseInputSerializer(serializer)
  .UseOutputSerializer(new BooleanSerializer());
  
var userCommand = this.GetCreateUserCommand(user);
return userService.Send(userCommand);

Supporting: T FromBytes(byte[]), byte[] ToBytes(T), string Serialize(T) and T Deserialize(string)

How about the struct?

Although the JsonSerializer could take care almost everything, however, in some cases we would also like to restrict the input/output into a certain type such as int or bool, thus this library also provides the below serializers for this purpose:

  • BooleanSerializer
  • Int16Serializer
  • Int32Serializer
What if no serializers suit my needs?

No one could promise that all requirements in this whole world are covered by their library, so if you are having any cases that the provided serializers don't fit, you could choose to extends ISerializer<T> which convert T between byte[], or extends ISerializer<T, TOutput> which convert T between TOutput.

Target Frameworks
  • .Net 4.6.1
  • .Net Standard 2.0
Product 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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on CodingCat.Serializers:

Package Downloads
CodingCat.Cache.Extensions

Package Description

CodingCat.RabbitMq.PubSub

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 1,428 2/15/2020