Can I get parameter names/values procedurally from the currently executing function?

Posted by Pwninstein on Stack Overflow See other posts from Stack Overflow or by Pwninstein
Published on 2010-03-08T22:19:21Z Indexed on 2010/03/08 22:21 UTC
Read the original article Hit count: 140

Filed under:
|
|
|

I would like to do something like this:

public MyFunction(int integerParameter, string stringParameter){
    //Do this:
    LogParameters();
    //Instead of this:
    //Log.Debug("integerParameter: " + integerParameter + 
    //          ", stringParameter: " + stringParameter);

}

public LogParameters(){
    //Look up 1 level in the call stack (if possible),
    //Programmatically loop through the function's parameters/values
    //and log them to a file (with the function name as well).
    //If I can pass a MethodInfo instead of analyzing the call stack, great.
}

I'm not even sure what I want to do is possible, but it would be very nice to be able to automatically output parameter names/values at runtime to a file without explicitly writing the code to log them.

Thanks!

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#