/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit.MessagePack/Serialization/MessagePackFormatters/InterfaceConcreteMapFormatter.cs
27 строк
1 KB
Marcus Christensen
Add support for MessagePack serialization.
15 окт 2024, 16:49
15 окт 2024, 16:49
faeebdf
Код
Авторство
О чём код?
namespace MassTransit.Serialization.MessagePackFormatters; using MessagePack; using MessagePack.Formatters; public class InterfaceConcreteMapFormatter<TInterface, TImplementation> : IMessagePackFormatter<TInterface> where TImplementation : TInterface { public virtual void Serialize(ref MessagePackWriter writer, TInterface value, MessagePackSerializerOptions options) { IMessagePackFormatter<TImplementation> innerFormatter = options.Resolver.GetFormatterWithVerify<TImplementation>(); if (value is TImplementation implementation) innerFormatter.Serialize(ref writer, implementation, options); else innerFormatter.Serialize(ref writer, (TImplementation)value!, options); } public virtual TInterface Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { IMessagePackFormatter<TImplementation> innerFormatter = options.Resolver.GetFormatterWithVerify<TImplementation>(); return innerFormatter.Deserialize(ref reader, options); } }