Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

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

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 data from it.

Yes, I know it's bad practice, I'm wondering if it's possible.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...