From 280496d238e158c351d05bcfb66226522c3c3f9d Mon Sep 17 00:00:00 2001 From: dongfo Date: Mon, 4 Mar 2019 11:26:14 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=A0=BC=E5=BC=8F=E8=B0=83=E6=95=B4=202.?= =?UTF-8?q?=E6=96=B0=E5=A2=9EFastActivator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PaySharp.Core/FastActivator.cs | 32 +++++++++++++++++++++++++++ src/PaySharp.Wechatpay/ConvertUtil.cs | 12 ++++------ 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 src/PaySharp.Core/FastActivator.cs diff --git a/src/PaySharp.Core/FastActivator.cs b/src/PaySharp.Core/FastActivator.cs new file mode 100644 index 0000000..e4ab82c --- /dev/null +++ b/src/PaySharp.Core/FastActivator.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Reflection; +using System.Linq.Expressions; + +namespace PaySharp.Core +{ + public static class FastActivator + { + public static Func Generate() + { + ConstructorInfo constructorInfo = typeof(TResult).GetConstructor(new Type[] { typeof(T), }); +#if DEBUG + ParameterInfo[] parameters = constructorInfo.GetParameters(); + ParameterExpression parameterExpression = Expression.Parameter(typeof(T), parameters[0].Name); +#else + ParameterExpression parameterExpression = Expression.Parameter(typeof(T)); +#endif + Expression> expression = Expression.Lambda>( + Expression.New( + constructorInfo, + parameterExpression), + parameterExpression); + Func functor = expression.Compile(); + return functor; + } + + } +} diff --git a/src/PaySharp.Wechatpay/ConvertUtil.cs b/src/PaySharp.Wechatpay/ConvertUtil.cs index c3a4c2f..8141027 100644 --- a/src/PaySharp.Wechatpay/ConvertUtil.cs +++ b/src/PaySharp.Wechatpay/ConvertUtil.cs @@ -10,14 +10,7 @@ namespace PaySharp.Wechatpay { internal static class ConvertUtil { - /// - /// 递归获取微信返回值列表 - /// - /// - /// - /// - /// - /// + public static List ToList(GatewayData gatewayData, int index) where T:new() where TChildren:new() { var flag = true; @@ -73,6 +66,7 @@ public static List ToList(GatewayData gatewayData, int index) w return list; } + /// /// 获取字段json中的名字 /// @@ -93,6 +87,7 @@ private static string GetRealName(System.Reflection.PropertyInfo item) return key; } + /// /// 将微信返回值特殊格式转化为列表 /// @@ -118,6 +113,7 @@ private static string GetRealName(System.Reflection.PropertyInfo item) } return list; } + /// /// 将微信返回值特殊格式转化为列表(二级) ///