mirror of https://github.com/abpframework/abp.git
8 changed files with 114 additions and 27 deletions
@ -0,0 +1,28 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Net.Http; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Http.Modeling; |
||||
|
|
||||
|
namespace Volo.Abp.Http.Client.ClientProxying.ExtraPropertyDictionaryConverts; |
||||
|
|
||||
|
public class ExtraPropertyDictionaryToFormData : IObjectToFormData<ExtraPropertyDictionary>, ITransientDependency |
||||
|
{ |
||||
|
public Task<List<KeyValuePair<string, HttpContent>>> ConvertAsync(ActionApiDescriptionModel actionApiDescription, ParameterApiDescriptionModel parameterApiDescription, ExtraPropertyDictionary extraPropertyDictionary) |
||||
|
{ |
||||
|
if (extraPropertyDictionary.IsNullOrEmpty()) |
||||
|
{ |
||||
|
return Task.FromResult<List<KeyValuePair<string, HttpContent>>>(null!); |
||||
|
} |
||||
|
|
||||
|
var formDataContents = new List<KeyValuePair<string, HttpContent>>(); |
||||
|
foreach (var item in extraPropertyDictionary) |
||||
|
{ |
||||
|
formDataContents.Add(new KeyValuePair<string, HttpContent>($"ExtraProperties[{item.Key}]", new StringContent(item.Value!.ToString()!, Encoding.UTF8))); |
||||
|
} |
||||
|
|
||||
|
return Task.FromResult(formDataContents); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Http.Modeling; |
||||
|
|
||||
|
namespace Volo.Abp.Http.Client.ClientProxying.ExtraPropertyDictionaryConverts; |
||||
|
|
||||
|
public class ExtraPropertyDictionaryToQueryString : IObjectToQueryString<ExtraPropertyDictionary>, ITransientDependency |
||||
|
{ |
||||
|
public Task<string> ConvertAsync(ActionApiDescriptionModel actionApiDescription, ParameterApiDescriptionModel parameterApiDescription, ExtraPropertyDictionary extraPropertyDictionary) |
||||
|
{ |
||||
|
if (extraPropertyDictionary.IsNullOrEmpty()) |
||||
|
{ |
||||
|
return Task.FromResult<string>(null!); |
||||
|
} |
||||
|
|
||||
|
var sb = new StringBuilder(); |
||||
|
foreach (var item in extraPropertyDictionary) |
||||
|
{ |
||||
|
sb.Append($"ExtraProperties[{item.Key}]={item.Value}&"); |
||||
|
} |
||||
|
if (sb.Length > 0) |
||||
|
{ |
||||
|
sb.Remove(sb.Length - 1, 1); |
||||
|
} |
||||
|
|
||||
|
return Task.FromResult(sb.ToString()); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue