CrystalSerializableAttribute

Namespace: SnowBank.Data · class

Implements: Attribute

Registers one or more types in a source-generated serializer container

Remarks

The registration is format-neutral: the registered type gets a generated serializer for every output format the container requests.

Any derived type, nested type, or type referenced by the members of these types is also included in the source code generation.

A registered type that implements IJsonSerializable, IJsonPackable or IJsonDeserializable<T> keeps its own format: the generated converter calls the type's method for each of those facets, and generates the other ones from its members. Set IgnoreCustomSerialization to take the members instead.

Do not subclass: the source generator matches exact attribute metadata names, a derived attribute is invisible to it.

Constructors

CrystalSerializableAttribute

CrystalSerializableAttribute(Type type)

Generates a serializer for instances of this type

  • type — Type that will have a source-generated serializer added to this container.

CrystalSerializableAttribute(params Type[] types)

Generates serializers for instances of the following types

  • types — List of types that will have a source-generated serializer added to this container.

Properties

IgnoreCustomSerialization

bool IgnoreCustomSerialization { get; set; }

Generates a member-based converter even when the type implements IJsonSerializable, IJsonPackable or IJsonDeserializable<T>

By default the generated converter calls the type's own method for each facet the type implements, so that a container and the runtime path produce the same bytes. This restores the member-based converter, for code that took a dependence on the member-based output.

Two limits, both by construction:

It cannot rescue a type the generator is unable to construct. A type with required members and no parameterless constructor does not compile when its converter is built from its members, whichever way this option is set.

It has no effect on a transitively-discovered type. Only the types named in a CrystalSerializableAttribute carry this option; the nested and referenced types the generator discovers carry no attribute of their own, and always keep their own format.

Types

Type[] Types { get; set; }

List of types to include in this container