Results 1 to 3 of 3

Thread: Reflection, Get Calling Method/Class Info [Resolved]

  1. #1

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Reflection, Get Calling Method/Class Info [Resolved]

    Is it possible to get the Name and Class of a method that calls a method.

    VB Code:
    1. 'This works for getting information about the calling assembly, but not anything more indepth.
    2.  
    3.  
    4. MsgBox("I was Called by: " & Reflection.Assembly.GetCallingAssembly.GetName.Name)
    Last edited by <ABX; Jul 26th, 2004 at 06:35 AM.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  2. #2
    Try this:
    VB Code:
    1. Dim method As System.Reflection.MethodBase
    2.  
    3. ' the calling method is always frame 1 of the call stack (the current method is frame 0):
    4. method = New System.Diagnostics.StackTrace().GetFrame(1).GetMethod()
    5.  
    6. ' show the name of the calling method:
    7. MessageBox.Show(method.Name)
    You can then use member.ReflectedType to get information about the class.

    No guarantees on performance here.
    Best regards,
    Andrew Young
    Skybound Software

  3. #3

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    Thanks

    Im not too worried about speed issue because this is for a debugging feature that will only be on when developing and testing.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width