示例#1
0
        /// <summary>
        /// Populates <paramref name="cloudEvent"/> with the data in <paramref name="data"/> by
        /// using the <see cref="ICloudEventDataConverter{T}"/> associated with <typeparamref name="T"/> via
        /// <see cref="CloudEventDataConverterAttribute"/>. See
        /// <see cref="ICloudEventDataConverter{T}.PopulateCloudEvent(CloudEvent, T)"/> for details of what gets populated.
        /// </summary>
        /// <param name="cloudEvent">The event to populate with data. Must not be null.</param>
        /// <param name="data">The data to populate within the event. May be null if the converter supports that.</param>
        public static void PopulateCloudEvent <T>(CloudEvent cloudEvent, T data) where T : class
        {
            EventsPreconditions.CheckNotNull(cloudEvent, nameof(cloudEvent));
            var converter = GetDataConverter <T>();

            converter.PopulateCloudEvent(cloudEvent, data);
        }
示例#2
0
        /// <summary>
        /// Converts the data in <paramref name="cloudEvent"/> into the type specified by <typeparamref name="T"/>,
        /// obtaining the <see cref="ICloudEventDataConverter{T}"/> associated with the type via <see cref="CloudEventDataConverterAttribute"/>.
        /// </summary>
        /// <typeparam name="T">The type to convert the event data to.</typeparam>
        /// <param name="cloudEvent">The CloudEvent to extract the data from. Must not be null.</param>
        /// <returns>The converted data.</returns>
        public static T ConvertCloudEventData <T>(CloudEvent cloudEvent) where T : class
        {
            EventsPreconditions.CheckNotNull(cloudEvent, nameof(cloudEvent));
            var converter = GetDataConverter <T>();

            return(converter.ConvertEventData(cloudEvent));
        }