AOP后锐化,记录变量值

问题描述 投票:0回答:1

使用postsharp,可以从属性获取变量值。此属性将在数据库或nlog中写入一些日志

[AOPTattribute($"The value of 'myint' is {myInt}")]
public void MyMethod()
{
    int myInt = (default) int;

    /*
    some code here  
    */
}

谢谢,

c# .net aop postsharp
1个回答
0
投票

简短的答案是,使用PostSharp Aspect Framework无法做到这一点。

PostSharp SDK(直接进行MSIL操作)将是可能的,但是开发成本可能会令人望而却步。您只需要方法末尾的变量值,就更简单了。如果要拦截所有直接分配给变量的操作,则会更加困难。如果您还想通过refout方法调用来拦截间接分配,则这是不可能的。

© www.soinside.com 2019 - 2024. All rights reserved.