How to get parameter value from StackTrace [duplicate]

限于喜欢 提交于 2020-01-20 06:21:51

问题


From within a method call I need to "jump" three layers up the stack and retrieve the type and value of the parameters passed to that method. Getting the parameter type is easy but I couldn't find a way to get the value passed to a certain method on the stack.

var st = new StackTrace();
var frames = st.GetFrames();
var methodParameters = frame[2].GetMethod().GetParameters;
// get each parameter value

Note: using StackTraceis not mandatory.

Is there a wayto find a value of a parameter passed to a method during runtime?


回答1:


I do not think there is a method unless you develop your own system for storing the values.

The reflection namespace represents static data about an assembly, and you would need to retrieve values at runtime.

I found PostSharp mentioned in MSDN forums, but I have never tried it.



来源:https://stackoverflow.com/questions/1820630/how-to-get-parameter-value-from-stacktrace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!