Dynamic C# proxying enhancements for culture sensitive types.

pull/3508/head
maliming 5 years ago
parent 86aee14c88
commit d6ca9ac7ec

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@ -106,20 +106,12 @@ namespace Volo.Abp.Http.Client.DynamicProxying
private async Task<T> MakeRequestAndGetResultAsync<T>(IAbpMethodInvocation invocation)
{
var responseAsString = await MakeRequestAsync(invocation);
//TODO: Think on that
if (TypeHelper.IsPrimitiveExtended(typeof(T), true))
if (typeof(T) == typeof(string))
{
if (typeof(DateTime).IsAssignableFrom(typeof(T)))
{
return (T)(object)DateTime.Parse(responseAsString.Trim('\"'), CultureInfo.InvariantCulture);
}
else
{
return (T)Convert.ChangeType(responseAsString, typeof(T));
}
responseAsString = responseAsString.EnsureStartsWith('"').EnsureEndsWith('"');
}
return JsonSerializer.Deserialize<T>(responseAsString);
}

@ -6,6 +6,7 @@ using System.Text;
using JetBrains.Annotations;
using Volo.Abp.Http.Modeling;
using Volo.Abp.Http.ProxyScripting.Generators;
using Volo.Abp.Localization;
using Volo.Abp.Reflection;
namespace Volo.Abp.Http.Client.DynamicProxying
@ -104,12 +105,15 @@ namespace Volo.Abp.Http.Client.DynamicProxying
private static string ConvertValueToString([NotNull] object value)
{
if (value is DateTime dateTimeValue)
using (CultureHelper.Use(CultureInfo.InvariantCulture))
{
return dateTimeValue.ToUniversalTime().ToString("u");
}
if (value is DateTime dateTimeValue)
{
return dateTimeValue.ToUniversalTime().ToString("u");
}
return value.ToString();
return value.ToString();
}
}
}
}

Loading…
Cancel
Save