[Aspect(Scope.Global)]
[Injection(typeof(LogCall))]
public class LogCall : Attribute
{
// kind 还可以After Around
[Advice(Kind.Before)]
public void LogEnter([Argument(Source.Name)] string name)
{
Console.WriteLine($"Calling '{name}' method..."); //这边是可以进行调试的
}
}
// async方法也是支持的
[LogCall]
public void Calculate()
{
Console.WriteLine("Calculated");
}
Calculate();
启动测试项目
dotnet run
会输出
Calling 'Calculate' method...
Calculated