C# reusable function to dump current value of local variables
问题 I would like to write a reusable function I can call within any method to log a snapshot of all the local variables. For example: void somemethod() { int a = 1; string s = "something"; dumpLocalVariables("step 1", MethodInfo.GetCurrentMethod(), this); a++; string t = s + "else"; dumpLocalVariables("step 2", MethodInfo.GetCurrentMethod(), this); } I would like to get a console output like this: step 1 Int32 a = 1 String s = something step 2 Int32 a = 2 String s = something String t =