Admin.Core/src/platform/ZhonTai.Admin/Core/Aop/AopHelper.cs
(完整代码) 1KBusing Castle.DynamicProxy;
using System;
using System.Reflection;
using System.Threading.Tasks;
namespace ZhonTai.Admin.Core.Aop;
public class AopHelper
{
public static async Task<T> ExecuteGenericMethod<T>(Task<T> returnValue, Action<T> callBackAction, Action<Exception> exceptionAction, Action finallyAction)
{
try
{
var result = await returnValue;
callBackAction?.Invoke(result);
return result;
}
catch (Exception ex)
{
exceptionAction?.Invoke(ex);
return default;
}
finally
{
finallyAction?.Invoke();
}
}
public static object CallGenericMethod(IInvocation invocation, Action<object> callBackAction, Action<Exception> exceptionAction, Action finallyAction)
{
return typeof(AopHelper)
.GetMethod("ExecuteGenericMethod", BindingFlags.Public | BindingFlags.Static)
.MakeGenericMethod(invocation.Method.ReturnType.GenericTypeArguments[0])
.Invoke(null, new object[] { invocation.ReturnValue, callBackAction, exceptionAction, finallyAction });
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
