Determine caller class name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • qingxun@gmail.com

    Determine caller class name

    Hi!

    Is there a way in VB.NET to determine the caller's class name?

    System.Reflecti on.MethodBase.G etCurrentMethod .GetType basically telling
    me what is my current executing class, but I wanted to know, which
    caller class invoke my existing class method.

    Any help is much appreciated.


    Bob

  • Oenone

    #2
    Re: Determine caller class name

    qingxun@gmail.c om wrote:[color=blue]
    > Is there a way in VB.NET to determine the caller's class name?[/color]

    \\\
    Dim stack As New StackTrace
    Dim className As String

    className = stack.GetFrame( 1).GetMethod.De claringType.Nam e
    ///

    The StackTrace object will contain details about the current call stack. The
    first element in the collection (element zero) will be your own current
    method, elements with higher indices will be the methods further up the
    call-stack. As the code that calls you will always be the second element on
    the call stack, you can access it using stack.GetFrame( 1).

    HTH,

    --

    (O)enone


    Comment

    • qingxun@gmail.com

      #3
      Re: Determine caller class name

      Thanks a lot. It definitely helps.

      Oenone wrote:[color=blue]
      > qingxun@gmail.c om wrote:[color=green]
      > > Is there a way in VB.NET to determine the caller's class name?[/color]
      >
      > \\\
      > Dim stack As New StackTrace
      > Dim className As String
      >
      > className = stack.GetFrame( 1).GetMethod.De claringType.Nam e
      > ///
      >
      > The StackTrace object will contain details about the current call stack. The
      > first element in the collection (element zero) will be your own current
      > method, elements with higher indices will be the methods further up the
      > call-stack. As the code that calls you will always be the second element on
      > the call stack, you can access it using stack.GetFrame( 1).
      >
      > HTH,
      >
      > --
      >
      > (O)enone[/color]

      Comment

      Working...