TheBoubou
TheBoubou

Reputation: 19933

AOP Postsharp, log the variables value

With postsharp is there a way from attribute to get variable value. This attribute will write some logs in database or nlog

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

    /*
    some code here  
    */
}

Thanks,

Upvotes: 2

Views: 108

Answers (1)

Gael Fraiteur
Gael Fraiteur

Reputation: 6857

The short answer is that this is not possible using PostSharp Aspect Framework.

It would be possible with PostSharp SDK (direct MSIL manipulation), but the cost of development will probably be prohibitive. It you just want the variable values at the end of the method, it's simpler. If you want to intercept all direct assignments to variables, it's more difficult. If you want to also intercept indirect assignments through ref and out method calls, this is impossible.

Upvotes: 2

Related Questions