MyloSoftworks.SerializeLib
1.0.4
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package MyloSoftworks.SerializeLib --version 1.0.4
NuGet\Install-Package MyloSoftworks.SerializeLib -Version 1.0.4
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="MyloSoftworks.SerializeLib" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MyloSoftworks.SerializeLib --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MyloSoftworks.SerializeLib, 1.0.4"
#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.
// Install MyloSoftworks.SerializeLib as a Cake Addin #addin nuget:?package=MyloSoftworks.SerializeLib&version=1.0.4 // Install MyloSoftworks.SerializeLib as a Cake Tool #tool nuget:?package=MyloSoftworks.SerializeLib&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SerializeLib
A library for serializing and deserializing in .net
Supported types
- Primitives
- bool, string, byte, short, int, long, float, double, decimal (and unsigned variants).
- Lists + arrays
- Lists and arrays can contain any supported types.
- Note: Lists/arrays with value of
null
will be deserialized as an empty list/array.
- Objects
- Any object which has the [SerializeClass] attribute can be serialized as a field as well.
- Objects with value of
null
will be deserialized asnull
as expected.
Usage
Defining a serializable object
- With attributes (automatic)
using SerializeLib.Attributes;
[SerializeClass]
public class SerializationExample {
[SerializeField] public bool ExampleBool;
}
- With interface (manual)
If you want to manually serialize data which can't be serialized yet, you can read/write the stream.
Make 100% sure that you read EXACTLY as many bytes as you write. Failure to do so will fail to deserialize.
using SerializeLib.Interfaces;
internal class ManualSerializeClass : ISerializableClass<ManualSerializeClass> {
public int Number = 0; // Lets serialize this int
public void Serialize(Stream s)
{
Serializer.SerializeValue(Number, s); // Generic, so type is auto-detected here
}
public ManualSerializeClass Deserialize(Stream s)
{
Number = Serializer.DeserializeValue<int>(s); // Generic, type is specified here
return this; // "return this;" is not a hard requirement, in some cases, you might want to return something else.
}
}
Serializing the object
using SerializeLib;
// Create an object to serialize
var exampleObject = new SerializationExample {
ExampleBool = true
}
// Serialize to a stream
var stream = new MemoryStream();
Serializer.Serialize(exampleObject, stream);
// Serialize to a byte[]
var bytes = Serializer.Serialize(exampleObject);
// Serialize and write to file
Serialize.SerializeToFile(exampleObject, "filename.bin")
Deserializing the object
using SerializeLib;
// Deserialize from a stream
var stream = new MemoryStream(); // In practice, this should be a stream with the serialized bytes
var exampleObject = Serializer.Deserialize<SerializationExample>(stream);
// Deserialize from a byte[]
var bytes = new byte[0]; // In practice, this should be a byte array with the serialized bytes
var exampleObject = Serializer.Deserialize<SerializationExample>();
// Deserialize from a file
var exampleObject = Serializer.DeserializeFromFile<SerializationExample>("filename.bin");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on MyloSoftworks.SerializeLib:
Package | Downloads |
---|---|
MyloSoftworks.PacketLib
Easy packet based networking on any protocol. |
|
MyloSoftworks.SerializeLib.archive
A file archive format using SerializeLib. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Update 1.0.4
+ Build dll as debug to prevent documentation from being removed