【问题标题】:AOP Postsharp, log the variables valueAOP Postsharp,记录变量值
【发布时间】:2020-04-04 01:19:00
【问题描述】:

使用 postsharp 有一种方法可以从属性获取变量值。该属性会在数据库或nlog中写入一些日志

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

    /*
    some code here  
    */
}

谢谢,

【问题讨论】:

    标签: c# .net aop postsharp


    【解决方案1】:

    简短的回答是使用 PostSharp Aspect Framework 是不可能的。

    PostSharp SDK(直接 MSIL 操作)可能会实现,但开发成本可能会令人望而却步。如果您只想要方法末尾的变量值,那就更简单了。如果你想拦截所有对变量的直接赋值,那就更难了。如果还想通过refout方法调用拦截间接赋值,这是不可能的。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多