Is it possible to access the line of code where a method is called from within that method?

Posted by Dan Tao on Stack Overflow See other posts from Stack Overflow or by Dan Tao
Published on 2010-05-18T17:14:50Z Indexed on 2010/05/18 17:20 UTC
Read the original article Hit count: 163

Filed under:
|

Disclaimers:

  • I am not interested in doing this in any real production code.
  • I make no claim that there's a good reason why I'm interested in doing this.
  • I realize that if this is in any way possible, it must involve doing some highly inadvisable things.

That said... is this possible? I'm really just curious to know.

In other words, if I have something like this:

int i = GetSomeInteger();

Is there any way from within GetSomeInteger that the code could be "aware of" the fact that it's being called in an assignment to the variable i?

Again: no interest in doing this in any sort of real scenario. Just curious!

© Stack Overflow or respective owner

Related posts about .NET

Related posts about reflection