Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 799613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:09:26+00:00 2026-05-14T23:09:26+00:00

Disclaimers: I am not interested in doing this in any real production code. I

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:09:26+00:00Added an answer on May 14, 2026 at 11:09 pm

    It’s possible using System.Diagnostics.StackTrace.

    For instance, you can get the name of the calling method like so:

        private static void stackExample()
        {
            var stack = new System.Diagnostics.StackTrace(true); // pass true to get more stack info
    
            var callingMethod = stack.GetFrame(1).GetMethod().Name;
            var callingLine = stack.GetFrame(1).GetFileLineNumber();
    
            Console.WriteLine("callingMethod: " + callingMethod + " on line " + callingLine.ToString());
        }
    

    http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.aspx

    This will not give you the line of code of the calling method, you’ll have to have access to the source code for that. stack.GetFrame(1).GetFileName() will give you the filename of the source code containing the method. What you can do from here, with the Method info and line number is to open the source file and get the line of code in question.

    GetMethod() gives you all sorts of great information, like which module the method exists in, then from there you can get the assembly information.

    It’s actually pretty fun to search through all of the metadata, it tells you all kinds of cool stuff about your code.

    The reason you cannot get the actual line of code is the source itself in C# form is not stored in the assembly. While you can get the IL, it’s a little more difficult to read. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DISCLAIMER: This is not a real-world example. It is just a theoretical question of
Disclaimer: I'm not a real developer, so I've probably got some code spaghetti here...
I have heard there is a branch of GHC that compiles to strict code
1st disclaimers: I'm not a programmer, never was had never been taught higher math
Disclaimer: not sure this is WordPress related or not. I'm following a simple tutorial
Disclaimer: this is not a question about how to install asp.net or an application
Disclaimer I am well aware that PHP might not have been the best choice
Disclaimer : I'm quite a novice to RoR, but not with Ruby (if that
Disclaimer: This is for a programming class, but it is not the answer or
Not so much a question to help my own programming, but I found this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.