From d6ca9ac7ec8a2c68f2d7b7082373a951cdaca2bf Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 7 Apr 2020 18:00:14 +0800 Subject: [PATCH] Dynamic C# proxying enhancements for culture sensitive types. --- .../DynamicHttpProxyInterceptor.cs | 18 +++++------------- .../Http/Client/DynamicProxying/UrlBuilder.cs | 12 ++++++++---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs index d5d90ed182..8d6f570309 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs @@ -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 MakeRequestAndGetResultAsync(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(responseAsString); } diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs index dae7853e08..162da88f16 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/UrlBuilder.cs @@ -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(); + } } } }