Class EnumSerializer<T>
Type serializer for enum values of type T.
Serializes enums as their string names for human readability and forward compatibility,
and falls back to integer parsing when deserializing values stored by older code.
Inherited Members
Namespace: Scylla.Core.Util.Serialization
Assembly: ScyllaCore.dll
Syntax
public sealed class EnumSerializer<T> : TypeSerializerBase<T>, ITypeSerializer<T>, ITypeSerializer where T : struct, Enum
Type Parameters
| Name | Description |
|---|---|
| T | The enum type to serialize. Must be a value type and implement Enum. |
Remarks
Enum values are written as their ToString() representation (e.g.
"Running", "Idle") rather than their underlying integer value.
This makes serialized data more readable and tolerant of enum value reordering.
During deserialization, the string is first parsed with
TryParse<TEnum>(string, out TEnum). If that fails, an attempt
is made to parse the string as an int and cast it, which provides
backwards compatibility with data serialized as numeric values by legacy code.
If both attempts fail, a SerializationException is thrown.
Instances are created on demand by GetSerializer(Type)
via reflection (Activator.CreateInstance) and are cached for subsequent
access.
Methods
Read(IScyllaReader, ISerializationContext)
Reads and returns a value of type T from the specified reader.
Declaration
public override T Read(IScyllaReader reader, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| IScyllaReader | reader | The reader positioned at the start of the serialized value. Never |
| ISerializationContext | context | The active serialization context, providing depth tracking, reference tracking,
and access to SerializationSettings. Never |
Returns
| Type | Description |
|---|---|
| T | The deserialized value of type |
Overrides
Write(T, IScyllaWriter, ISerializationContext)
Writes a value of type T to the specified writer.
Declaration
public override void Write(T value, IScyllaWriter writer, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to serialize. For reference types this may be |
| IScyllaWriter | writer | The writer that receives the serialized output. Never |
| ISerializationContext | context | The active serialization context, providing depth tracking, reference tracking,
and access to SerializationSettings. Never |