1+ using Hyperion ;
2+ using NServiceBus . Configuration . AdvanceExtensibility ;
3+ using NServiceBus . Serialization ;
4+ using NServiceBus . Settings ;
5+ using NServiceBus . Hyperion ;
6+
7+ namespace NServiceBus
8+ {
9+
10+ /// <summary>
11+ /// Extensions for <see cref="SerializationExtensions{T}"/> to manipulate how messages are serialized via Jil.
12+ /// </summary>
13+ public static class HyperionConfigurationExtensions
14+ {
15+
16+ /// <summary>
17+ /// Configures the <see cref="SerializerOptions"/> to use.
18+ /// </summary>
19+ /// <param name="config">The <see cref="SerializationExtensions{T}"/> instance.</param>
20+ /// <param name="options">The <see cref="SerializerOptions"/> to use.</param>
21+ public static void Options ( this SerializationExtensions < HyperionSerializer > config , SerializerOptions options )
22+ {
23+ Guard . AgainstNull ( config , nameof ( config ) ) ;
24+ var settings = config . GetSettings ( ) ;
25+ settings . Set < SerializerOptions > ( options ) ;
26+ }
27+
28+ internal static SerializerOptions GetOptions ( this ReadOnlySettings settings )
29+ {
30+ return settings . GetOrDefault < SerializerOptions > ( ) ;
31+ }
32+
33+ /// <summary>
34+ /// Configures string to use for <see cref="Headers.ContentType"/> headers.
35+ /// </summary>
36+ /// <remarks>
37+ /// Defaults to "hyperion".
38+ /// </remarks>
39+ /// <param name="config">The <see cref="SerializationExtensions{T}"/> instance.</param>
40+ /// <param name="contentTypeKey">The content type key to use.</param>
41+ public static void ContentTypeKey ( this SerializationExtensions < HyperionSerializer > config , string contentTypeKey )
42+ {
43+ Guard . AgainstNull ( config , nameof ( config ) ) ;
44+ Guard . AgainstNullOrEmpty ( contentTypeKey , nameof ( contentTypeKey ) ) ;
45+ var settings = config . GetSettings ( ) ;
46+ settings . Set ( "NServiceBus.Hyperion.ContentTypeKey" , contentTypeKey ) ;
47+ }
48+
49+ internal static string GetContentTypeKey ( this ReadOnlySettings settings )
50+ {
51+ return settings . GetOrDefault < string > ( "NServiceBus.Hyperion.ContentTypeKey" ) ;
52+ }
53+ }
54+ }
0 commit comments