Version 3.3.0.1

BaseFormatter<T> class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public abstract class BaseFormatter<T> : IFormatter<T>, IFormatter
Provides common functionality for serializing and deserializing values of type , and provides automatic support for the following common serialization conventions:

System.Runtime.Serialization.IObjectReference, , System.Runtime.Serialization.OnSerializingAttribute, System.Runtime.Serialization.OnSerializedAttribute, System.Runtime.Serialization.OnDeserializingAttribute and System.Runtime.Serialization.OnDeserializedAttribute.

Inheritance
  • System.Object
  • BaseFormatter<T>
See Also
  • Sirenix.Serialization.IFormatter<T>

Type Parameters

T

The type which can be serialized and deserialized by the formatter.

Constructors

BaseFormatter()
protected BaseFormatter()

Fields

ImplementsIDeserializationCallback
protected static readonly bool ImplementsIDeserializationCallback
ImplementsIObjectReference
protected static readonly bool ImplementsIObjectReference
ImplementsISerializationCallbackReceiver
protected static readonly bool ImplementsISerializationCallbackReceiver
IsValueType
Whether the serialized value is a value type.
protected static readonly bool IsValueType
OnDeserializedCallbacks
The on deserialized callbacks for type .
protected static readonly BaseFormatter<T>.SerializationCallback[] OnDeserializedCallbacks
OnDeserializingCallbacks
The on deserializing callbacks for type .
protected static readonly BaseFormatter<T>.SerializationCallback[] OnDeserializingCallbacks
OnSerializedCallbacks
The on serialized callbacks for type .
protected static readonly BaseFormatter<T>.SerializationCallback[] OnSerializedCallbacks
OnSerializingCallbacks
The on serializing callbacks for type .
protected static readonly BaseFormatter<T>.SerializationCallback[] OnSerializingCallbacks

Properties

SerializedType
Gets the type that the formatter can serialize.
public Type SerializedType { get; }

Methods

Deserialize(IDataReader)
Deserializes a value of type using a specified Sirenix.Serialization.IDataReader.
public T Deserialize(IDataReader reader)
Parameters
Sirenix.Serialization.IDataReader reader

The reader to use.

Returns
T

The deserialized value.

DeserializeImplementation(ref T, IDataReader)
Provides the actual implementation for deserializing a value of type .
protected abstract void DeserializeImplementation(ref T value, IDataReader reader)
Parameters
T value

The uninitialized value to serialize into. This value will have been created earlier using GetUninitializedObject().

Sirenix.Serialization.IDataReader reader

The reader to deserialize with.

GetUninitializedObject()
Get an uninitialized object of type . WARNING: If you override this and return null, the object's ID will not be automatically registered and its OnDeserializing callbacks will not be automatically called, before deserialization begins. You will have to call RegisterReferenceID(T, IDataReader) and InvokeOnDeserializingCallbacks(ref T, DeserializationContext) immediately after creating the object yourself during deserialization.
protected virtual T GetUninitializedObject()
Returns
T

An uninitialized object of type .

InvokeOnDeserializingCallbacks(ref T, DeserializationContext)
Invokes all methods on the object with the [OnDeserializing] attribute.

WARNING: This method will not be called automatically if you override GetUninitializedObject and return null! You will have to call it manually after having created the object instance during deserialization.

protected void InvokeOnDeserializingCallbacks(ref T value, DeserializationContext context)
Parameters
T value

The value to invoke the callbacks on.

DeserializationContext context

The deserialization context.

RegisterReferenceID(T, IDataReader)
Registers the given object reference in the deserialization context.

NOTE that this method only does anything if is not a value type.

protected void RegisterReferenceID(T value, IDataReader reader)
Parameters
T value

The value to register.

Sirenix.Serialization.IDataReader reader

The reader which is currently being used.

Serialize(T, IDataWriter)
Serializes a value of type using a specified Sirenix.Serialization.IDataWriter.
public void Serialize(T value, IDataWriter writer)
Parameters
T value

The value to serialize.

Sirenix.Serialization.IDataWriter writer

The writer to use.

SerializeImplementation(ref T, IDataWriter)
Provides the actual implementation for serializing a value of type .
protected abstract void SerializeImplementation(ref T value, IDataWriter writer)
Parameters
T value

The value to serialize.

Sirenix.Serialization.IDataWriter writer

The writer to serialize with.