mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2026-02-11 10:16:20 +08:00
refactor(tenpayv3): 优化反射性能
This commit is contained in:
@@ -23,7 +23,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
|
||||
|
||||
try
|
||||
{
|
||||
bool requireEncrypt = request.GetType().GetCustomAttributes<WechatTenpaySensitiveAttribute>(inherit: true).Any();
|
||||
bool requireEncrypt = Attribute.IsDefined(request.GetType(), typeof(WechatTenpaySensitiveAttribute));
|
||||
if (requireEncrypt)
|
||||
{
|
||||
// 遍历并加密被标记为敏感数据的字段
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
|
||||
return response;
|
||||
}
|
||||
|
||||
bool requireDecrypt = response.GetType().GetCustomAttributes<WechatTenpaySensitiveAttribute>(inherit: true).Any();
|
||||
bool requireDecrypt = Attribute.IsDefined(response.GetType(), typeof(WechatTenpaySensitiveAttribute));
|
||||
if (requireDecrypt)
|
||||
{
|
||||
// 遍历并解密被标记为敏感数据的字段
|
||||
|
||||
@@ -4,9 +4,24 @@ using System.Reflection;
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -28,7 +43,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var childProp in objType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
foreach (var childProp in GetTypedProperties(objType))
|
||||
{
|
||||
if (!childProp.CanWrite)
|
||||
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