MyloSoftworks.SerializeLib 1.0.4

There is a newer version of this package available.
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                
#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                

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 as null as expected.

Usage

Defining a serializable object

  1. With attributes (automatic)
using SerializeLib.Attributes;

[SerializeClass]
public class SerializationExample {
    [SerializeField] public bool ExampleBool;
}
  1. 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 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.

Version Downloads Last updated
1.1.0 91 7/14/2024
1.0.9 101 7/12/2024
1.0.8 78 7/10/2024
1.0.7 92 7/3/2024
1.0.6 95 7/1/2024
1.0.5 132 6/29/2024
1.0.4 85 6/29/2024
1.0.3 94 6/28/2024
1.0.2 107 6/28/2024
1.0.1 92 6/28/2024
1.0.0 81 6/25/2024

Update 1.0.4
+ Build dll as debug to prevent documentation from being removed