Access method name in the method itself

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mukesh

    #1

    Access method name in the method itself

    Hi,

    Could I write a code that will get the method name within which the
    code is written.
    like I want

    void showMethodName( ){
    string method;
    method=Need a method here to get the method name which contains this
    code. In this case it is "showMethodName "
    }

    Thanks
    Chakravarti Mukesh

  • Ciaran O''Donnell

    #2
    RE: Access method name in the method itself

    methodname = new System.Diagnost ics.StackTrace( ).GetFrame(0).G etMethod().Name ;

    Ciaran O'Donnell

    "Mukesh" wrote:
    Hi,
    >
    Could I write a code that will get the method name within which the
    code is written.
    like I want
    >
    void showMethodName( ){
    string method;
    method=Need a method here to get the method name which contains this
    code. In this case it is "showMethodName "
    }
    >
    Thanks
    Chakravarti Mukesh
    >
    >

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Access method name in the method itself

      Mukesh <cmukesh19@gmai l.comwrote:
      Could I write a code that will get the method name within which the
      code is written.
      like I want
      >
      void showMethodName( ){
      string method;
      method=Need a method here to get the method name which contains this
      code. In this case it is "showMethodName "
      }
      Ciaran showed you a way, but it should be noted that this is quite
      expensive, and should almost always be avoided.

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      If replying to the group, please do not mail me too

      Comment

      Working...