开发者

Reflect up 5 levels for a Property?

开发者 https://www.devze.com 2023-02-28 16:48 出处:网络
I have implemented a CustomTraceListener for use with Enterprise Library 5. From the TraceData method, I need to crawl the stack up 6 levels to my class that had the actual logging call, I need a prop

I have implemented a CustomTraceListener for use with Enterprise Library 5. From the TraceData method, I need to crawl the stack up 6 levels to my class that had the actual logging call, I need a property from the开发者_运维技巧re. I don't think I want a StackFrame climb because that only gets the class and not the object, right? What is the best way to get at the (string) property I need?

This is on Framework 4.0, thanks.


I don't think you can get (parameters) values from the .NET stack from the program itself, only methods, properties, classes, ie: anything that comes from .NET metadata.

If you want values, here are a some solutions:

  • instrument your code before compilation, adding lines of code to capture parameters values
  • instrument your code after compilation, with things like PostSharp for example (disclaimer: I'm not affiliated in any way)
  • write a .NET profiler, but this must be an external program. There a existing tools that do this already, like this one: CLR profiler. Version 4 of the CLR profiler (available here) comes with the source.
0

精彩评论

暂无评论...
验证码 换一张
取 消