Define a contract and many implementations for working with many technologies for serialization
- SerializeToStream
- SerializeToStreamAsync
- SerializeToString
- DeserializeFromStream
- DeserializeFromString
- DeserializeFromStreamAsync
Use the latest nuget published of EA.Serializers.Contracts and the desire nuget of the implementation
- .Net 6.0
- System.Text.Json
- Newtonsoft
- MessagePack
At this point, it is possible to use that asset:
- Cloning the repo and use it directly on you solution. On this way, you will have access too entire code.
- Using the dll located on Release folder
var stream = new MemoryStream();
var item = new Item(); //Item can be any obj
//you can choose between many impl
ISerializer serializer = new ErniAcademy.Serializers.Json.JsonSerializer();
ISerializer serializer = new ErniAcademy.Serializers.NewtonsoftJson.JsonSerializer();
ISerializer serializer = new ErniAcademy.Serializers.MessagePack.MessagePackSerializer(); //keep in mind that for Message pack you will need to add [DataContract] and [DataMembers] attributes
//serialize
await serializer.SerializeToStreamAsync(item, stream);
//at this point you can do what you want with the stream that contain your item, for example you can upload the stream to a blob e.g. https://docs.microsoft.com/en-us/dotnet/api/azure.storage.blobs.blobclient.uploadasync?view=azure-dotnet#azure-storage-blobs-blobclient-uploadasync(system-io-stream-system-boolean-system-threading-cancellationtoken)
//deserialize
var deserializedItem = await serializer.DeserializeFromStreamAsync<Item>(stream);
//at this point you will get your item instance
- take care about that sample are instances directly. In general situation, we should use DI.
- take a look at the UnitTests project to see it samples of use
Please see our Contribution Guide to learn how to contribute.
(LICENSE) © 2022 ERNI - Swiss Software Engineering
Please see our Code of Conduct
Thanks goes to these wonderful people (emoji key):
omaramalfi 💻 🖋 📖 🎨 🤔 🚧 |
This project follows the all-contributors specification. Contributions of any kind welcome!