Skip to content

Commit

Permalink
1.格式调整
Browse files Browse the repository at this point in the history
2.新增FastActivator
  • Loading branch information
dongfo committed Mar 4, 2019
1 parent 1e0c28e commit 280496d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
32 changes: 32 additions & 0 deletions src/PaySharp.Core/FastActivator.cs
Original file line number Diff line number Diff line change
@@ -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<T, TResult> Generate<T, TResult>()
{
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<Func<T, TResult>> expression = Expression.Lambda<Func<T, TResult>>(
Expression.New(
constructorInfo,
parameterExpression),
parameterExpression);
Func<T, TResult> functor = expression.Compile();
return functor;
}

}
}
12 changes: 4 additions & 8 deletions src/PaySharp.Wechatpay/ConvertUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ namespace PaySharp.Wechatpay
{
internal static class ConvertUtil
{
/// <summary>
/// 递归获取微信返回值列表
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TChildren"></typeparam>
/// <param name="gatewayData"></param>
/// <param name="index"></param>
/// <returns></returns>

public static List<T> ToList<T, TChildren>(GatewayData gatewayData, int index) where T:new() where TChildren:new()
{
var flag = true;
Expand Down Expand Up @@ -73,6 +66,7 @@ public static List<T> ToList<T, TChildren>(GatewayData gatewayData, int index) w

return list;
}

/// <summary>
/// 获取字段json中的名字
/// </summary>
Expand All @@ -93,6 +87,7 @@ private static string GetRealName(System.Reflection.PropertyInfo item)

return key;
}

/// <summary>
/// 将微信返回值特殊格式转化为列表
/// </summary>
Expand All @@ -118,6 +113,7 @@ private static string GetRealName(System.Reflection.PropertyInfo item)
}
return list;
}

/// <summary>
/// 将微信返回值特殊格式转化为列表(二级)
/// </summary>
Expand Down

0 comments on commit 280496d

Please sign in to comment.