/
vshmidt
/
masstransit
Обзор
Документация
Войти
/
vshmidt
/
masstransit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/MassTransit/Initializers/PropertyInitializers/DictionaryCopyPropertyInitializer.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.Collections.Generic; using System.Reflection; using System.Threading.Tasks; using Internals; /// <summary> /// Gets the dictionary entry for the property (if present), and sets the message property to the value /// </summary> /// <typeparam name="TMessage"></typeparam> /// <typeparam name="TInput"></typeparam> /// <typeparam name="TProperty"></typeparam> public class DictionaryCopyPropertyInitializer<TMessage, TInput, TProperty> : IPropertyInitializer<TMessage, TInput> where TMessage : class where TInput : class, IDictionary<string, TProperty> { readonly string _key; readonly IWriteProperty<TMessage, TProperty> _messageProperty; public DictionaryCopyPropertyInitializer(PropertyInfo propertyInfo, string key) { if (propertyInfo == null) throw new ArgumentNullException(nameof(propertyInfo)); _key = key; _messageProperty = WritePropertyCache<TMessage>.GetProperty<TProperty>(propertyInfo); } public Task Apply(InitializeContext<TMessage, TInput> context) { if (context.HasInput && context.Input.TryGetValue(_key, out var value)) _messageProperty.Set(context.Message, value); return Task.CompletedTask; } } }