从StackTrace获取方法参数值 [英] Getting method parameters values from StackTrace

查看:100
本文介绍了从StackTrace获取方法参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试编写一个通用记录器,将从每个方法条目中调用该记录器.
记录器应打印方法名称和输入值-如果有的话,可以通过查询stacktrace.

是否可以在不显式传递值的情况下获取值?

更好的方法是为每个方法打印带有实际参数值的stacktrace(例如记录异常时).

只是要清楚-我不是要解决调用堆栈(即:哪个方法调用了哪个方法),而是要如何为每个方法传递值

tx

Jammusi

Hi,
I'm trying to write a generic logger the will be called from each method entry
The logger should print the method name and the input values - if any by querying the stacktrace.

Is there a way to get the values without passing them explicitly?

Even better would be to print the stacktrace with the actual parameters values for each method (when logging exception for instance).

Just to be clear - I am not asking about resolving the call stack (that is: what method called which one) but rather how to get the values passed for each method

tx

Jammusi

推荐答案

您可以使用反射来找出参数的名称和类型,但无法获得实际值.

You can figure out the names and types of the parameters using reflection but you cannot get the actual values.


这篇关于从StackTrace获取方法参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆