Class SerializationContext
Default implementation of ISerializationContext created internally by ScyllaSerialization for each top-level serialization or deserialization call.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Serialization
Assembly: ScyllaCore.dll
Syntax
public sealed class SerializationContext : ISerializationContext
Remarks
SerializationContext is not intended for direct instantiation in application code. It is constructed by ScyllaSerialization with the appropriate SerializationSettings, ReferenceTracker, and serializer resolver delegate, then passed down through the engine to every type serializer involved in the operation.
Serializer resolution follows a two-stage priority order:
- Per-operation custom serializers stored in CustomSerializers (registered via RegisterSerializer<T>(ITypeSerializer<T>)).
-
The global serializer registry maintained by
SerializationEngine, supplied at construction time via the
serializerResolverdelegate.
Constructors
SerializationContext(SerializationSettings, ReferenceTracker, Func<Type, ITypeSerializer>)
Initializes a new SerializationContext for a single serialization or deserialization operation.
Declaration
public SerializationContext(SerializationSettings settings, ReferenceTracker referenceTracker, Func<Type, ITypeSerializer> serializerResolver = null)
Parameters
| Type | Name | Description |
|---|---|---|
| SerializationSettings | settings | The settings that control format, depth limits, null/default-value handling, and
per-operation custom serializers. Must not be |
| ReferenceTracker | referenceTracker | The tracker used to detect and manage cyclic object references throughout the
operation. Must not be |
| Func<Type, ITypeSerializer> | serializerResolver | An optional delegate that maps a Type to its globally registered
ITypeSerializer. When |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
Properties
CurrentDepth
Gets the zero-based nesting depth at which the engine is currently operating.
The depth starts at 0 for the root object and increments by one for each
nested object or collection encountered.
Declaration
public int CurrentDepth { get; }
Property Value
| Type | Description |
|---|---|
| int | An integer in the range |
See Also
IsMaxDepthReached
Gets a value indicating whether the operation has reached the maximum allowed
nesting depth as defined by MaxDepth.
When true, the next call to PushDepth() will throw a
SerializationException.
Declaration
public bool IsMaxDepthReached { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
ReferenceTracker
Gets the reference tracker that monitors object identity across the entire operation, enabling cycle detection and, when Preserve is active, reference ID assignment and resolution.
Declaration
public ReferenceTracker ReferenceTracker { get; }
Property Value
| Type | Description |
|---|---|
| ReferenceTracker | The ReferenceTracker instance shared for the duration of this
operation. Never |
See Also
Settings
Gets the settings that govern the current serialization or deserialization operation, including the chosen output format, null/default-value handling policies, maximum recursion depth, and any per-operation custom type serializers.
Declaration
public SerializationSettings Settings { get; }
Property Value
| Type | Description |
|---|---|
| SerializationSettings | The SerializationSettings instance provided when the operation started.
Never |
Methods
GetSerializer(Type)
Returns the most specific ITypeSerializer registered for the
specified runtime type, or null if no serializer
is registered for that type.
Declaration
public ITypeSerializer GetSerializer(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The exact Type for which a serializer is required. Must not be
|
Returns
| Type | Description |
|---|---|
| ITypeSerializer | An ITypeSerializer capable of handling |
See Also
GetSerializer<T>()
Returns a strongly-typed ITypeSerializer<T> for the type
parameter T, or null if no typed serializer
has been registered for that type.
Declaration
public ITypeSerializer<T> GetSerializer<T>()
Returns
| Type | Description |
|---|---|
| ITypeSerializer<T> | An ITypeSerializer<T> for |
Type Parameters
| Name | Description |
|---|---|
| T | The compile-time type for which a serializer is required. |
See Also
PopDepth()
Decrements the current nesting depth by one level to signal that the engine
has finished serializing or deserializing a nested object or collection.
Safe to call when depth is already 0 - it is a no-op in that case.
Declaration
public void PopDepth()
See Also
PushDepth()
Increments the current nesting depth by one level to signal that the engine is entering a nested object or collection. Must be paired with a subsequent call to PopDepth().
Declaration
public void PushDepth()
Exceptions
| Type | Condition |
|---|---|
| SerializationException | Thrown when the incremented depth would exceed MaxDepth, which typically indicates either a circular reference that bypassed ReferenceTracker or a legitimate but unusually deep object graph. |