11using System ;
2- using System . IO ;
32using System . Linq . Expressions ;
4- using System . Runtime . CompilerServices ;
5- using System . Threading . Tasks ;
63
74namespace Dibix . Http . Server
85{
@@ -12,19 +9,36 @@ internal sealed class BodyParameterSourceProvider : NonUserParameterSourceProvid
129
1310 public override void Resolve ( IHttpParameterResolutionContext context )
1411 {
15- if ( context . PropertyPath != BodyParameterSource . RawPropertyName )
12+ switch ( context . PropertyPath )
1613 {
17- Type instanceType = context . ActionMetadata . SafeGetBodyContract ( ) ;
18- Expression instanceValue = Expression . Call ( typeof ( HttpParameterResolverUtility ) , nameof ( HttpParameterResolverUtility . ReadBody ) , new [ ] { instanceType } , context . ArgumentsParameter ) ;
19- context . ResolveUsingInstanceProperty ( instanceType , instanceValue , ensureNullPropagation : true ) ;
20- }
21- else
22- {
23- // TODO: Can be null!
24- Expression getBodyCall = Expression . Call ( context . RequestParameter , nameof ( IHttpRequestDescriptor . GetBody ) , Type . EmptyTypes ) ;
25- Expression getAwaiterCall = Expression . Call ( getBodyCall , typeof ( Task < Stream > ) . SafeGetMethod ( nameof ( Task < Stream > . GetAwaiter ) ) ) ;
26- Expression getResultCall = Expression . Call ( getAwaiterCall , nameof ( TaskAwaiter . GetResult ) , Type . EmptyTypes ) ;
27- context . ResolveUsingValue ( getResultCall ) ;
14+ case BodyParameterSource . RawPropertyName :
15+ {
16+ Expression getBodyCall = Expression . Call ( context . RequestParameter , nameof ( IHttpRequestDescriptor . GetBody ) , Type . EmptyTypes ) ;
17+ context . ResolveUsingValue ( getBodyCall ) ;
18+ break ;
19+ }
20+
21+ case BodyParameterSource . MediaTypePropertyName :
22+ {
23+ Expression getBodyMediaTypeCall = Expression . Call ( context . RequestParameter , nameof ( IHttpRequestDescriptor . GetBodyMediaType ) , Type . EmptyTypes ) ;
24+ context . ResolveUsingValue ( getBodyMediaTypeCall ) ;
25+ break ;
26+ }
27+
28+ case BodyParameterSource . FileNamePropertyName :
29+ {
30+ Expression getBodyFileNameCall = Expression . Call ( context . RequestParameter , nameof ( IHttpRequestDescriptor . GetBodyFileName ) , Type . EmptyTypes ) ;
31+ context . ResolveUsingValue ( getBodyFileNameCall ) ;
32+ break ;
33+ }
34+
35+ default :
36+ {
37+ Type instanceType = context . ActionMetadata . SafeGetBodyContract ( ) ;
38+ Expression instanceValue = Expression . Call ( typeof ( HttpParameterResolverUtility ) , nameof ( HttpParameterResolverUtility . ReadBody ) , [ instanceType ] , context . ArgumentsParameter ) ;
39+ context . ResolveUsingInstanceProperty ( instanceType , instanceValue , ensureNullPropagation : true ) ;
40+ break ;
41+ }
2842 }
2943 }
3044 }
0 commit comments