mirror of https://github.com/abpframework/abp.git
10 changed files with 215 additions and 121 deletions
@ -0,0 +1,11 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Net.Http; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.Http |
||||
|
{ |
||||
|
public interface IObjectToFormData<in TValue> |
||||
|
{ |
||||
|
Task<List<KeyValuePair<string, HttpContent>>> ConvertAsync(TValue value); |
||||
|
} |
||||
|
} |
||||
@ -1,44 +0,0 @@ |
|||||
using System.Collections.Generic; |
|
||||
using System.Text; |
|
||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
using Volo.Abp.Http; |
|
||||
|
|
||||
namespace Volo.Abp.TestApp.Application.Dto |
|
||||
{ |
|
||||
public class GetParamsFromQueryInput |
|
||||
{ |
|
||||
public List<GetParamsFromQueryInputNameValue> NameValues { get; set; } |
|
||||
|
|
||||
public GetParamsFromQueryInputNameValue NameValue { get; set; } |
|
||||
} |
|
||||
|
|
||||
public class GetParamsFromQueryInputNameValue |
|
||||
{ |
|
||||
public string Name { get; set; } |
|
||||
|
|
||||
public string Value { get; set; } |
|
||||
} |
|
||||
|
|
||||
[ExposeServices(typeof(IObjectToQueryString<List<GetParamsFromQueryInputNameValue>>))] |
|
||||
public class TestInputToQueryString : IObjectToQueryString<List<GetParamsFromQueryInputNameValue>>, ITransientDependency |
|
||||
{ |
|
||||
public Task<string> ConvertAsync(List<GetParamsFromQueryInputNameValue> values) |
|
||||
{ |
|
||||
if (values.IsNullOrEmpty()) |
|
||||
{ |
|
||||
return null; |
|
||||
} |
|
||||
|
|
||||
var sb = new StringBuilder(); |
|
||||
|
|
||||
for (var i = 0; i < values.Count; i++) |
|
||||
{ |
|
||||
sb.Append($"NameValues[{i}].Name={values[i].Name}&NameValues[{i}].Value={values[i].Value}&"); |
|
||||
} |
|
||||
|
|
||||
sb.Remove(sb.Length - 1, 1); |
|
||||
return Task.FromResult(sb.ToString()); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,66 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Net.Http; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Http; |
||||
|
|
||||
|
namespace Volo.Abp.TestApp.Application.Dto |
||||
|
{ |
||||
|
public class GetParamsInput |
||||
|
{ |
||||
|
public List<GetParamsNameValue> NameValues { get; set; } |
||||
|
|
||||
|
public GetParamsNameValue NameValue { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class GetParamsNameValue |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public string Value { get; set; } |
||||
|
} |
||||
|
|
||||
|
[ExposeServices(typeof(IObjectToQueryString<List<GetParamsNameValue>>))] |
||||
|
public class TestObjectToQueryString : IObjectToQueryString<List<GetParamsNameValue>>, ITransientDependency |
||||
|
{ |
||||
|
public Task<string> ConvertAsync(List<GetParamsNameValue> values) |
||||
|
{ |
||||
|
if (values.IsNullOrEmpty()) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
var sb = new StringBuilder(); |
||||
|
|
||||
|
for (var i = 0; i < values.Count; i++) |
||||
|
{ |
||||
|
sb.Append($"NameValues[{i}].Name={values[i].Name}&NameValues[{i}].Value={values[i].Value}&"); |
||||
|
} |
||||
|
|
||||
|
sb.Remove(sb.Length - 1, 1); |
||||
|
return Task.FromResult(sb.ToString()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[ExposeServices(typeof(IObjectToFormData<List<GetParamsNameValue>>))] |
||||
|
public class TestObjectToFormData : IObjectToFormData<List<GetParamsNameValue>>, ITransientDependency |
||||
|
{ |
||||
|
public Task<List<KeyValuePair<string, HttpContent>>> ConvertAsync(List<GetParamsNameValue> values) |
||||
|
{ |
||||
|
if (values.IsNullOrEmpty()) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
var formDataContents = new List<KeyValuePair<string, HttpContent>>(); |
||||
|
for (var i = 0; i < values.Count; i++) |
||||
|
{ |
||||
|
formDataContents.Add(new KeyValuePair<string, HttpContent>($"NameValues[{i}].Name", new StringContent(values[i].Name, Encoding.UTF8))); |
||||
|
formDataContents.Add(new KeyValuePair<string, HttpContent>($"NameValues[{i}].Value", new StringContent(values[i].Value, Encoding.UTF8))); |
||||
|
} |
||||
|
|
||||
|
return Task.FromResult(formDataContents); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue