Icepack 1.1.0

dotnet add package Icepack --version 1.1.0
NuGet\Install-Package Icepack -Version 1.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="Icepack" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Icepack --version 1.1.0
#r "nuget: Icepack, 1.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.
// Install Icepack as a Cake Addin
#addin nuget:?package=Icepack&version=1.1.0

// Install Icepack as a Cake Tool
#tool nuget:?package=Icepack&version=1.1.0

ICEPACK

Icepack is a lightweight binary serialization library for C#.

It was specifically developed to address limitations that other serialization libraries have when serializing inheritance-based hierarchies, and to make it easy for code frameworks to implement serializable base classes.

Features

  • Object references are preserved by default, although this can be disabled globally.
  • The serializer serializes all fields by default, but can be configured to only serialize fields annotated with the SerializableField attribute. Fields can be ignored by the serializer by annotating them with the IgnoreField attribute.
  • The format slightly favours deserialization performance over serialization performance. This is often important for games since the end-user is usually more affected by load times.
  • Types can be included for serialization by calling the serializer's RegisterType method, or annotating the type with the SerializableType attribute.
  • Fields can be ignored by annotating them with the IgnoreField attribute.
  • The ISerializationListener interface is provided to allow classes and structs to execute additional logic before serialization and after deserialization.
  • Readonly fields are supported.
  • Interfaces are supported.
  • Boxed value types are supported.
  • The serializer can handle derived and base classes that define fields with the same name.
  • The serializer can call private constructors.
  • Arrays, and List<T>, HashSet<T>, and Dictionary<T> are registered automatically, but their generic parameter types must be registered explicitly.
  • Deserialization is somewhat resilient to changes to the data types since serialization:
    • Fields that have been added/removed to/from a class since serialization will be ignored.
    • A field that was serialized as a reference to an instance of a missing class is ignored.
    • If a class was derived from another class that is now missing or is no longer a base class, the missing or former base class is ignored, and the serializer resumes deserializing fields from further ancestors.
    • The PreviousName attribute can be assigned to a field to indicate that the name of the field has changed, so that the correct field will be matched with what is in the serialized data.

Limitations

  • Only fields (both private and public) are serialized, not properties.
  • nuint, nint, and delegates are not supported.
  • Deserializing after changing the type of a serialized field results in undefined behaviour.
  • Changing the name of a type will result in the serializer ignoring objects of that type.

Examples

Registering Types

Types must be registered before they can be serialized. Types can be lazy-registered by annotating them with the SerializableType attribute.

[SerializableType]
public class ExampleType { }

Types can also be registered via the serializer's RegisterType method. This is necessary in order to serialize types defined in third-party libraries.

var serializer = new Serializer();
serializer.RegisterType(typeof(ExampleType));

Serialization and Deserialization

The serializer serializes and deserializes an object graph to and from a stream.

var serializer = new Serializer();

var obj = new ExampleType();

var stream = new MemoryStream();
serializer.Serialize(obj, stream);
stream.Position = 0;
ExampleType? deserializedObj = serializer.Deserialize<ExampleType>(stream);
stream.Close();

Serialization Callbacks

The ISerializationListener is used to execute logic immediately before serialization and after deserialization.

[SerializableType]
public class ExampleClass : ISerializationListener
{
  public int Field;

  public void OnBeforeSerialize()
  {
    Console.WriteLine("Before serializing.");
  }

  public void OnAfterDeserialize()
  {
    Console.WriteLine("After deserialized.");
  }
}
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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 405 9/10/2022
1.0.8 403 7/21/2022
1.0.7 398 7/20/2022
1.0.6 406 7/18/2022
1.0.5 408 7/16/2022
1.0.4 374 10/9/2021
1.0.3 346 10/9/2021
1.0.2 296 10/5/2021
1.0.1 343 10/4/2021
1.0.0 308 10/4/2021

Fixes and tweaks.