Version 2.1.0.0

Serializer class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public abstract class Serializer
Serializes and deserializes a given type, and wraps serialization and deserialization with all the proper calls to free formatters from tedious boilerplate.

Whenever serializing or deserializing anything, it is *strongly recommended* to use Get<T>() to get a proper wrapping serializer for that type.

NOTE: This class should NOT be inherited from; it is hard-coded into the system.

To extend the serialization system, instead create custom formatters, which are used by the ComplexTypeSerializer<T> class.

Inheritance
  • System.Object
  • Serializer

Constructors

Serializer()
protected Serializer()

Methods

FireOnSerializedType(Type)
Fires the OnSerializedType event.
[Conditional("UNITY_EDITOR")]
protected static void FireOnSerializedType(Type type)
Parameters
System.Type type

Get(Type)
Gets a Serializer for the given type.
public static Serializer Get(Type type)
Parameters
System.Type type

The type to get a Serializer for.

Returns
Serializer

A Serializer for the given type.

Exceptions
System.ArgumentNullException

The type argument is null.

Get<T>()
Gets a Serializer for type T.
public static Serializer<T> Get<T>()
Returns
Serializer<T>

A Serializer for type T.

Type Parameters
T

The type to get a Serializer for.

GetForValue(Object)
Gets a Serializer for the given value. If the value is null, it will be treated as a value of type System.Object.
public static Serializer GetForValue(object value)
Parameters
System.Object value

The value to get a Serializer for.

Returns
Serializer

A Serializer for the given value.

ReadValueWeak(IDataReader)
Reads a value weakly, casting it into object. Use this method if you don't know what type you're going to be working with at compile time.
public abstract object ReadValueWeak(IDataReader reader)
Parameters
Sirenix.Serialization.IDataReader reader

The reader to use.

Returns
System.Object

The value which has been read.

WriteValueWeak(Object, IDataWriter)
Writes a weakly typed value. Use this method if you don't know what type you're going to be working with at compile time.
public void WriteValueWeak(object value, IDataWriter writer)
Parameters
System.Object value

The value to write.

Sirenix.Serialization.IDataWriter writer

The writer to use.

WriteValueWeak(String, Object, IDataWriter)
Writes a weakly typed value with a given name. Use this method if you don't know what type you're going to be working with at compile time.
public abstract void WriteValueWeak(string name, object value, IDataWriter writer)
Parameters
System.String name

The name of the value to write.

System.Object value

The value to write.

Sirenix.Serialization.IDataWriter writer

The writer to use.

Events

OnSerializedType
Editor-only event that fires whenever a serializer serializes a type.
public static event Action<Type> OnSerializedType
Derived Classes

This website is brand new and built with the Odin 2.1 beta in mind. This means you might discover some features such as attribute expressions that are only available in the beta.

You can download the 2.1 beta from here and read the patch-notes here.