Class ValueObjectProtoModelExtensions
Namespace: AdCodicem.ValueObjects.ProtobufNet
Assembly: AdCodicem.ValueObjects.ProtobufNet.dll
Registers the serializers of value objects on a protobuf-net
public static class ValueObjectProtoModelExtensions
Inheritance
object ← ValueObjectProtoModelExtensions
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
protobuf-net adds a member's type to a model only when the type carries a contract attribute, so a value object it was
not told about fails the first contract that holds one: "No serializer defined for type". These methods tell it, at
start-up, before the model serializes anything: RuntimeTypeModel.Default.AddValueObjects(typeof(Sku).Assembly)
serves Serializer.Serialize and protobuf-net.Grpc's default binder.
Each value object gets the serializer of .proto export as the scalar protobuf-net names its underlying type at that level,
string or int32, with the import a .bcl.Guid or a .google.protobuf.Timestamp needs.
A value object the model already serializes some way keeps it: one given a serializer type on the model, or by
[ProtoContract(Serializer = …)] on the type, which is named in the export only when the serializer is one of
this package's over a profile it ships and the attribute gives no Name.
These methods serve protobuf-net's runtime model, which emits code at run time: under native AOT, a value object names
its serializer with [ProtoContract(Serializer = …)], and the application serializes through protobuf-net's
compile-time model, a [ProtoModel].
Methods
AddValueObject<TSelf, TValue>(RuntimeTypeModel, bool)
Registers the serializer of one value object, a construction of a generic one or one written by hand included, without reflection.
[RequiresDynamicCode("protobuf-net's runtime model emits code at run time; under native AOT, name the serializer on the value object with [ProtoContract(Serializer = ...)] and serialize through a [ProtoModel].")]
public static RuntimeTypeModel AddValueObject<TSelf, TValue>(this RuntimeTypeModel model, bool trusted = false) where TSelf : struct, IValueObject<TSelf, TValue>
Parameters
model RuntimeTypeModel
The model,
trusted bool
Whether reads skip validation, for bytes the application alone wrote; false, the default, reads through the value object's rules.
Returns
RuntimeTypeModel
model, for chaining.
Type Parameters
TSelf
Value object type, Reference<PurchaseOrder> for instance.
TValue
Underlying value type.
Exceptions
model is null.
protobuf-net has no inbuilt serializer for TValue.
The model already serializes TSelf through another serializer type: one of the other trust,
one of the application's own, or the one [ProtoContract(Serializer = …)] names on the type.
AddValueObjects(RuntimeTypeModel, params Assembly[])
Registers, strict, a serializer for every value object the registry holds, once the generated registration of the assemblies given has run.
[RequiresUnreferencedCode("Locates the generated registration of each assembly given by its metadata.")]
[RequiresDynamicCode("protobuf-net's runtime model emits code at run time; under native AOT, name the serializer on the value object with [ProtoContract(Serializer = ...)] and serialize through a [ProtoModel].")]
public static RuntimeTypeModel AddValueObjects(this RuntimeTypeModel model, params Assembly[] assemblies)
Parameters
model RuntimeTypeModel
The model,
assemblies Assembly[]
Assemblies declaring value objects, whose generated registration runs first.
Returns
RuntimeTypeModel
model, for chaining.
Exceptions
model or assemblies is null.
AddValueObjects(RuntimeTypeModel, bool, params Assembly[])
Registers, trusted or strict, a serializer for every value object the registry holds, once the generated registration of the assemblies given has run.
[RequiresUnreferencedCode("Locates the generated registration of each assembly given by its metadata.")]
[RequiresDynamicCode("protobuf-net's runtime model emits code at run time; under native AOT, name the serializer on the value object with [ProtoContract(Serializer = ...)] and serialize through a [ProtoModel].")]
public static RuntimeTypeModel AddValueObjects(this RuntimeTypeModel model, bool trusted, params Assembly[] assemblies)
Parameters
model RuntimeTypeModel
The model,
trusted bool
Whether reads skip validation, for bytes the application alone wrote, a cache or a store among them; false reads through the value objects' rules.
assemblies Assembly[]
Assemblies declaring value objects, whose generated registration runs first.
Returns
RuntimeTypeModel
model, for chaining.
Remarks
A construction of a generic value object and a value object written by hand are in the registry only once something
registered them:
Exceptions
model or assemblies is null.