Question
Can I get parameter names/values procedurally from the currently executing function?
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.
Is it possible?