如何从堆栈跟踪参数值 [英] How to get parameter value from StackTrace

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

问题描述

从一个方法调用中我需要跳三层堆栈向上和检索传递给方法的参数的类型和值。 获取参数的类型是容易的,但我不能找到一个办法让传递到堆栈上一定的方法的价值。

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?

推荐答案

我不觉得有什么,除非你开发自己的系统,用于存储值的方法。

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

反射命名空间重新presents有关程序集的静态的数据,你需要在运行时检索值。

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

我发现 PostSharp 在MSDN论坛中提到,但我从来没有尝试过。

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

这篇关于如何从堆栈跟踪参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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