mirror of https://github.com/abpframework/abp.git
7 changed files with 126 additions and 25 deletions
@ -0,0 +1,27 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using Volo.Abp.Http.Modeling; |
||||
|
using Volo.Abp.Reflection; |
||||
|
|
||||
|
namespace Volo.Abp.Http.Client.DynamicProxying |
||||
|
{ |
||||
|
internal static class HttpActionParameterHelper |
||||
|
{ |
||||
|
public static object FindParameterValue(IReadOnlyDictionary<string, object> methodArguments, ParameterApiDescriptionModel apiParameter) |
||||
|
{ |
||||
|
var value = methodArguments[apiParameter.NameOnMethod]; |
||||
|
if (value == null) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
if (apiParameter.Name == apiParameter.NameOnMethod) |
||||
|
{ |
||||
|
return value; |
||||
|
} |
||||
|
|
||||
|
return ReflectionHelper.GetValueByPath(value, value.GetType(), apiParameter.Name); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using Volo.Abp.Http.Modeling; |
||||
|
using Volo.Abp.Json; |
||||
|
|
||||
|
namespace Volo.Abp.Http.Client.DynamicProxying |
||||
|
{ |
||||
|
public static class RequestPayloadBuilder |
||||
|
{ |
||||
|
public static string GenerateBody(ActionApiDescriptionModel action, IReadOnlyDictionary<string, object> methodArguments, IJsonSerializer jsonSerializer) |
||||
|
{ |
||||
|
var parameters = action |
||||
|
.Parameters |
||||
|
.Where(p => p.BindingSourceId == "Body") |
||||
|
.ToArray(); |
||||
|
|
||||
|
if (parameters.Length <= 0) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
if (parameters.Length > 1) |
||||
|
{ |
||||
|
throw new AbpException( |
||||
|
$"Only one complex type allowed as argument to a controller action that's binding source is 'Body'. But action on URL: {action.Url} contains more than one!" |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
var value = HttpActionParameterHelper.FindParameterValue(methodArguments, parameters[0]); |
||||
|
if (value == null) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
return jsonSerializer.Serialize(value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue