mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2026-03-10 00:13:36 +08:00
refactor(tenpayv3): 优化反射性能
This commit is contained in:
@@ -23,7 +23,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bool requireEncrypt = request.GetType().GetCustomAttributes<WechatTenpaySensitiveAttribute>(inherit: true).Any();
|
bool requireEncrypt = Attribute.IsDefined(request.GetType(), typeof(WechatTenpaySensitiveAttribute));
|
||||||
if (requireEncrypt)
|
if (requireEncrypt)
|
||||||
{
|
{
|
||||||
// 遍历并加密被标记为敏感数据的字段
|
// 遍历并加密被标记为敏感数据的字段
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool requireDecrypt = response.GetType().GetCustomAttributes<WechatTenpaySensitiveAttribute>(inherit: true).Any();
|
bool requireDecrypt = Attribute.IsDefined(response.GetType(), typeof(WechatTenpaySensitiveAttribute));
|
||||||
if (requireDecrypt)
|
if (requireDecrypt)
|
||||||
{
|
{
|
||||||
// 遍历并解密被标记为敏感数据的字段
|
// 遍历并解密被标记为敏感数据的字段
|
||||||
|
|||||||
@@ -4,9 +4,24 @@ using System.Reflection;
|
|||||||
|
|
||||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
|
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
|
||||||
{
|
{
|
||||||
internal static class ReflectionUtility
|
internal static partial class ReflectionUtility
|
||||||
{
|
{
|
||||||
public delegate (bool Modified, string NewValue) ReplacePropertyStringValueReplacementHandler(object target, PropertyInfo currentProp, string oldValue);
|
private static readonly Hashtable _typeProperties = new Hashtable();
|
||||||
|
|
||||||
|
private static PropertyInfo[] GetTypedProperties(Type type)
|
||||||
|
{
|
||||||
|
if (type == null) throw new ArgumentNullException(nameof(type));
|
||||||
|
|
||||||
|
string skey = type.AssemblyQualifiedName ?? type.GetHashCode().ToString();
|
||||||
|
PropertyInfo[]? properties = (PropertyInfo[]?)_typeProperties[skey];
|
||||||
|
if (properties == null)
|
||||||
|
{
|
||||||
|
properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||||
|
_typeProperties[skey] = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
public static void ReplacePropertyStringValue<T>(ref T obj, ReplacePropertyStringValueReplacementHandler replacement)
|
public static void ReplacePropertyStringValue<T>(ref T obj, ReplacePropertyStringValueReplacementHandler replacement)
|
||||||
{
|
{
|
||||||
@@ -28,7 +43,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var childProp in objType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
foreach (var childProp in GetTypedProperties(objType))
|
||||||
{
|
{
|
||||||
if (!childProp.CanWrite)
|
if (!childProp.CanWrite)
|
||||||
continue;
|
continue;
|
||||||
@@ -188,4 +203,9 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial class ReflectionUtility
|
||||||
|
{
|
||||||
|
public delegate (bool Modified, string NewValue) ReplacePropertyStringValueReplacementHandler(object target, PropertyInfo currentProp, string oldValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user