public sealed class EnumSerializer<TEnum> where TEnum : unmanaged, EnumReads and writes an enum as an element of a collection.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
An enum member never needs this and that is why it was missing. DataContractGenerator resolves a member of enum type to MemberShape.Enum and emits writer.WriteInt32((int)value.Direction) inline, so no enum type has ever needed a registered serializer — and DataContractGenerator.Describe returns nothing for TypeKind.Enum deliberately, on exactly that reasoning.
⚠ An enum element takes the other path, and there was no value of that member shape that serialised. WriteArray<T>, WriteList<T> and WriteDictionary<K,V> ask the registry and then call WriteElement, which for a value type with no serializer throws — and the exception told the author to annotate the enum with [DataContract], which the generator explicitly declines to act on. So Facing[], List<Facing> and Dictionary<string, Facing> were all unserialisable and no annotation an author could write changed that (#1177).
⚠ The generator instantiates it, and it has to be the generator. SerializerRegistry cannot build the closed generic at run time — NativeAOT has no MakeGenericType, and the whole registry is built on that constraint — so the set of enums a build can read is decided by what the compiler saw. It is the same mechanism ContentReferenceSerializer{T} reaches the registry by, emitted from the same module initialiser.
The bytes are the member path's bytes. Each primitive writer is fixed-width little-endian, so writing the underlying value at the enum's own width produces exactly what writer.WriteInt32((int)…) would have — an enum moved between a member and a collection element does not change the stream. As``2 rather than a cast because a cast needs the underlying type named, which generic code does not have; reinterpreting the reference reads the value in native order and the writer puts it out little-endian, which is correct on either endianness rather than only on the one Vixen runs on.
Methods (2)
public override void Serialize(ref SerializationWriter writer, in TEnum value)Writes a value.
public override void Deserialize(ref SerializationReader reader, ref TEnum value)Reads a value into .
Used by (1)
- SerializerRegistrationVixen.Core.Serialization.Tests