Version 3.3.0.1

SerializationUtility class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public static class SerializationUtility
Provides an array of utility wrapper methods for easy serialization and deserialization of objects of any type.
Inheritance
  • System.Object
  • SerializationUtility

Methods

CreateCopy(Object)
Creates a deep copy of an object. Returns null if null. All Unity objects references will remain the same - they will not get copied. Similarly, strings are not copied, nor are reflection types such as System.Type, or types derived from System.Reflection.MemberInfo, System.Reflection.Assembly or System.Reflection.Module.
public static object CreateCopy(object obj)
Parameters
System.Object obj

Returns
System.Object

CreateReader(Stream, DeserializationContext, DataFormat)
Creates an Sirenix.Serialization.IDataReader for a given format.
public static IDataReader CreateReader(Stream stream, DeserializationContext context, DataFormat format)
Parameters
System.IO.Stream stream

The stream to read from.

DeserializationContext context

The deserialization context to use.

DataFormat format

The format to read.

Returns
Sirenix.Serialization.IDataReader

An Sirenix.Serialization.IDataReader for a given format.

Exceptions
System.NotImplementedException

CreateWriter(Stream, SerializationContext, DataFormat)
Creates an Sirenix.Serialization.IDataWriter for a given format.
public static IDataWriter CreateWriter(Stream stream, SerializationContext context, DataFormat format)
Parameters
System.IO.Stream stream

The stream to write to.

SerializationContext context

The serialization context to use.

DataFormat format

The format to write.

Returns
Sirenix.Serialization.IDataWriter

An Sirenix.Serialization.IDataWriter for a given format.

Exceptions
System.NotImplementedException

DeserializeValue<T>(IDataReader)
Deserializes a value from the given reader.
public static T DeserializeValue<T>(IDataReader reader)
Parameters
Sirenix.Serialization.IDataReader reader

The reader to use.

Returns
T

The deserialized value.

Type Parameters
T

The type to deserialize.

DeserializeValue<T>(IDataReader, List<Object>)
Deserializes a value of a given type from the given reader, using the given list of Unity objects for external index reference resolution.
public static T DeserializeValue<T>(IDataReader reader, List<Object> referencedUnityObjects)
Parameters
Sirenix.Serialization.IDataReader reader

The reader to use.

System.Collections.Generic.List<UnityEngine.Object> referencedUnityObjects

The list of Unity objects to use for external index reference resolution.

Returns
T

The deserialized value.

Type Parameters
T

The type to deserialize.

DeserializeValue<T>(Byte[], DataFormat, DeserializationContext)
Deserializes a value of a given type from the given byte array in the given format.
public static T DeserializeValue<T>(byte[] bytes, DataFormat format, DeserializationContext context = null)
Parameters
System.Byte[] bytes

The bytes to deserialize from.

DataFormat format

The format to read.

DeserializationContext context

The context to use.

Returns
T

The deserialized value.

Type Parameters
T

The type to deserialize.

DeserializeValue<T>(Byte[], DataFormat, List<Object>, DeserializationContext)
Deserializes a value of a given type from the given byte array in the given format, using the given list of Unity objects for external index reference resolution.
public static T DeserializeValue<T>(byte[] bytes, DataFormat format, List<Object> referencedUnityObjects, DeserializationContext context = null)
Parameters
System.Byte[] bytes

The bytes to deserialize from.

DataFormat format

The format to read.

System.Collections.Generic.List<UnityEngine.Object> referencedUnityObjects

The list of Unity objects to use for external index reference resolution.

DeserializationContext context

The context to use.

Returns
T

The deserialized value.

Type Parameters
T

The type to deserialize.

DeserializeValue<T>(Stream, DataFormat, DeserializationContext)
Deserializes a value of a given type from the given stream in the given format.
public static T DeserializeValue<T>(Stream stream, DataFormat format, DeserializationContext context = null)
Parameters
System.IO.Stream stream

The stream to read from.

DataFormat format

The format to read.

DeserializationContext context

The context.

Returns
T

The deserialized value.

Type Parameters
T

The type to deserialize.

DeserializeValue<T>(Stream, DataFormat, List<Object>, DeserializationContext)
Deserializes a value of a given type from the given stream in the given format, using the given list of Unity objects for external index reference resolution.
public static T DeserializeValue<T>(Stream stream, DataFormat format, List<Object> referencedUnityObjects, DeserializationContext context = null)
Parameters
System.IO.Stream stream

The stream to read from.

DataFormat format

The format to read.

System.Collections.Generic.List<UnityEngine.Object> referencedUnityObjects

The list of Unity objects to use for external index reference resolution.

DeserializationContext context

The context.

Returns
T

The deserialized value.

Type Parameters
T

The type to deserialize.

DeserializeValueWeak(IDataReader)
Deserializes a value from the given reader. This might fail with primitive values, as they don't come with metadata.
public static object DeserializeValueWeak(IDataReader reader)
Parameters
Sirenix.Serialization.IDataReader reader

The reader to use.

Returns
System.Object

The deserialized value.

DeserializeValueWeak(IDataReader, List<Object>)
Deserializes a value from the given reader, using the given list of Unity objects for external index reference resolution. This might fail with primitive values, as they don't come with type metadata.
public static object DeserializeValueWeak(IDataReader reader, List<Object> referencedUnityObjects)
Parameters
Sirenix.Serialization.IDataReader reader

The reader to use.

System.Collections.Generic.List<UnityEngine.Object> referencedUnityObjects

The list of Unity objects to use for external index reference resolution.

Returns
System.Object

The deserialized value.

DeserializeValueWeak(Byte[], DataFormat, DeserializationContext)
Deserializes a value from the given byte array in the given format. This might fail with primitive values, as they don't come with type metadata.
public static object DeserializeValueWeak(byte[] bytes, DataFormat format, DeserializationContext context = null)
Parameters
System.Byte[] bytes

The bytes to deserialize from.

DataFormat format

The format to read.

DeserializationContext context

The context.

Returns
System.Object

The deserialized value.

DeserializeValueWeak(Byte[], DataFormat, List<Object>)
Deserializes a value from the given byte array in the given format, using the given list of Unity objects for external index reference resolution. This might fail with primitive values, as they don't come with type metadata.
public static object DeserializeValueWeak(byte[] bytes, DataFormat format, List<Object> referencedUnityObjects)
Parameters
System.Byte[] bytes

The bytes to deserialize from.

DataFormat format

The format to read.

System.Collections.Generic.List<UnityEngine.Object> referencedUnityObjects

The list of Unity objects to use for external index reference resolution.

Returns
System.Object

The deserialized value.

DeserializeValueWeak(Stream, DataFormat, DeserializationContext)
Deserializes a value from the given stream in the given format. This might fail with primitive values, as they don't come with type metadata.
public static object DeserializeValueWeak(Stream stream, DataFormat format, DeserializationContext context = null)
Parameters
System.IO.Stream stream

The reader to use.

DataFormat format

The format to read.

DeserializationContext context

The context.

Returns
System.Object

The deserialized value.

DeserializeValueWeak(Stream, DataFormat, List<Object>, DeserializationContext)
Deserializes a value from the given stream in the given format, using the given list of Unity objects for external index reference resolution. This might fail with primitive values, as they don't come with type metadata.
public static object DeserializeValueWeak(Stream stream, DataFormat format, List<Object> referencedUnityObjects, DeserializationContext context = null)
Parameters
System.IO.Stream stream

The stream to read from.

DataFormat format

The format to read.

System.Collections.Generic.List<UnityEngine.Object> referencedUnityObjects

The list of Unity objects to use for external index reference resolution.

DeserializationContext context

The context.

Returns
System.Object

The deserialized value.

SerializeValue<T>(T, DataFormat, SerializationContext)
Serializes the given value using the specified format, and returns the result as a byte array.
public static byte[] SerializeValue<T>(T value, DataFormat format, SerializationContext context = null)
Parameters
T value

The value to serialize.

DataFormat format

The format to use.

SerializationContext context

The context to use.

Returns
System.Byte[]

A byte array containing the serialized value.

Type Parameters
T

The type of the value to serialize.

SerializeValue<T>(T, DataFormat, out List<Object>, SerializationContext)
Serializes the given value using the specified format and returns the result as a byte array.
public static byte[] SerializeValue<T>(T value, DataFormat format, out List<Object> unityObjects, SerializationContext context = null)
Parameters
T value

The value to serialize.

DataFormat format

The format to use.

System.Collections.Generic.List<UnityEngine.Object> unityObjects

A list of the Unity objects which were referenced during serialization.

SerializationContext context

The context to use.

Returns
System.Byte[]

A byte array containing the serialized value.

Type Parameters
T

The type of the value to serialize.

SerializeValue<T>(T, IDataWriter)
Serializes the given value using the given writer.
public static void SerializeValue<T>(T value, IDataWriter writer)
Parameters
T value

The value to serialize.

Sirenix.Serialization.IDataWriter writer

The writer to use.

Type Parameters
T

The type of the value to serialize.

SerializeValue<T>(T, IDataWriter, out List<Object>)
Serializes the given value, using the given writer.
public static void SerializeValue<T>(T value, IDataWriter writer, out List<Object> unityObjects)
Parameters
T value

The value to serialize.

Sirenix.Serialization.IDataWriter writer

The writer to use.

System.Collections.Generic.List<UnityEngine.Object> unityObjects

A list of the Unity objects which were referenced during serialization.

Type Parameters
T

The type of the value to serialize.

SerializeValue<T>(T, Stream, DataFormat, SerializationContext)
Serializes the given value to a given stream in the specified format.
public static void SerializeValue<T>(T value, Stream stream, DataFormat format, SerializationContext context = null)
Parameters
T value

The value to serialize.

System.IO.Stream stream

The stream to serialize to.

DataFormat format

The format to serialize in.

SerializationContext context

The context.

Type Parameters
T

The type of the value to serialize.

SerializeValue<T>(T, Stream, DataFormat, out List<Object>, SerializationContext)
Serializes the given value to a given stream in the specified format.
public static void SerializeValue<T>(T value, Stream stream, DataFormat format, out List<Object> unityObjects, SerializationContext context = null)
Parameters
T value

The value to serialize.

System.IO.Stream stream

The stream to serialize to.

DataFormat format

The format to serialize in.

System.Collections.Generic.List<UnityEngine.Object> unityObjects

A list of the Unity objects which were referenced during serialization.

SerializationContext context

The context.

Type Parameters
T

The type of the value to serialize.

SerializeValueWeak(Object, DataFormat, SerializationContext)
Serializes the given value using the specified format, and returns the result as a byte array.
public static byte[] SerializeValueWeak(object value, DataFormat format, SerializationContext context = null)
Parameters
System.Object value

The value to serialize.

DataFormat format

The format to use.

SerializationContext context

The context.

Returns
System.Byte[]

A byte array containing the serialized value.

SerializeValueWeak(Object, DataFormat, out List<Object>)
Serializes the given value using the specified format, and returns the result as a byte array.
public static byte[] SerializeValueWeak(object value, DataFormat format, out List<Object> unityObjects)
Parameters
System.Object value

The value to serialize.

DataFormat format

The format to use.

System.Collections.Generic.List<UnityEngine.Object> unityObjects

A list of the Unity objects which were referenced during serialization.

Returns
System.Byte[]

A byte array containing the serialized value.

SerializeValueWeak(Object, IDataWriter)
Serializes the given value using the given writer.
public static void SerializeValueWeak(object value, IDataWriter writer)
Parameters
System.Object value

The value to serialize.

Sirenix.Serialization.IDataWriter writer

The writer to use.

SerializeValueWeak(Object, IDataWriter, out List<Object>)
Serializes the given value, using the given writer.
public static void SerializeValueWeak(object value, IDataWriter writer, out List<Object> unityObjects)
Parameters
System.Object value

The value to serialize.

Sirenix.Serialization.IDataWriter writer

The writer to use.

System.Collections.Generic.List<UnityEngine.Object> unityObjects

A list of the Unity objects which were referenced during serialization.

SerializeValueWeak(Object, Stream, DataFormat, SerializationContext)
Serializes the given value to a given stream in the specified format.
public static void SerializeValueWeak(object value, Stream stream, DataFormat format, SerializationContext context = null)
Parameters
System.Object value

The value to serialize.

System.IO.Stream stream

The stream to serialize to.

DataFormat format

The format to serialize in.

SerializationContext context

The context.

SerializeValueWeak(Object, Stream, DataFormat, out List<Object>, SerializationContext)
Serializes the given value to a given stream in the specified format.
public static void SerializeValueWeak(object value, Stream stream, DataFormat format, out List<Object> unityObjects, SerializationContext context = null)
Parameters
System.Object value

The value to serialize.

System.IO.Stream stream

The stream to serialize to.

DataFormat format

The format to serialize in.

System.Collections.Generic.List<UnityEngine.Object> unityObjects

A list of the Unity objects which were referenced during serialization.

SerializationContext context

The context.