CodingCat.Serializers
0.1.0
dotnet add package CodingCat.Serializers --version 0.1.0
NuGet\Install-Package CodingCat.Serializers -Version 0.1.0
<PackageReference Include="CodingCat.Serializers" Version="0.1.0" />
<PackageVersion Include="CodingCat.Serializers" Version="0.1.0" />
<PackageReference Include="CodingCat.Serializers" />
paket add CodingCat.Serializers --version 0.1.0
#r "nuget: CodingCat.Serializers, 0.1.0"
#:package CodingCat.Serializers@0.1.0
#addin nuget:?package=CodingCat.Serializers&version=0.1.0
#tool nuget:?package=CodingCat.Serializers&version=0.1.0
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 | 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 | 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. |
-
.NETFramework 4.6.1
- Newtonsoft.Json (>= 12.0.3)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 12.0.3)
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 |