Is there any way to get a reference to the calling object in c#?

前端 未结 3 1971
遥遥无期
遥遥无期 2020-12-03 09:59

What I\'m wondering is if it\'s possible to (for instance) to walk up the stack frames, checking each calling object to see if matches an interface, and if so extract some d

3条回答
  •  没有蜡笔的小新
    2020-12-03 10:52

    No, there isn't - at least not without using a profiling/debugging API of some description. You can walk the stack to find the calling method, with the caveat that it's really slow and may be inaccurate due to JIT optimisations. That won't tell you what the calling object is though (if indeed there is one).

提交回复
热议问题