/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit/Initializers/PropertyInitializers/CopyPropertyInitializer.cs
41 строка
1 KB
Chris Patterson
Integration of all external packages into MassTransit, split out into Abstractions, Middleware, and the core MassTransit assembly.
22 янв 2022, 18:24
22 янв 2022, 18:24
b5b4f50
Код
Авторство
О чём код?
namespace MassTransit.Initializers.PropertyInitializers { using System; using System.Reflection; using System.Threading.Tasks; using Internals; /// <summary> /// Set a message property by copying the input property (of the same type), regardless of whether /// the input property value is null, etc. /// </summary> /// <typeparam name="TMessage"></typeparam> /// <typeparam name="TInput"></typeparam> /// <typeparam name="TProperty"></typeparam> public class CopyPropertyInitializer<TMessage, TInput, TProperty> : IPropertyInitializer<TMessage, TInput> where TMessage : class where TInput : class { readonly IReadProperty<TInput, TProperty> _inputProperty; readonly IWriteProperty<TMessage, TProperty> _messageProperty; public CopyPropertyInitializer(PropertyInfo messagePropertyInfo, PropertyInfo inputPropertyInfo) { if (messagePropertyInfo == null) throw new ArgumentNullException(nameof(messagePropertyInfo)); _inputProperty = ReadPropertyCache<TInput>.GetProperty<TProperty>(inputPropertyInfo); _messageProperty = WritePropertyCache<TMessage>.GetProperty<TProperty>(messagePropertyInfo); } public Task Apply(InitializeContext<TMessage, TInput> context) { if (context.HasInput) _messageProperty.Set(context.Message, _inputProperty.Get(context.Input)); return Task.CompletedTask; } } }