Get class name and class method

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

Hi guys,
I am implementing a loging system in my app and I need a way to get name of
current class and name of the current method, so I can pass them to my
loging system.

Also I want to asign an ID to each method, so I can pass it to the loging
system.
But it is not easy to remeber which is the last ID I've used, so I can
assign a new ID to newly created methods. Any ideas how to accomplish this.

TIA
 
Hi Nikolay

Try this for starters:

Dim tString As String = Me.GetType().Name ' Class name
Dim s As New System.Diagnostics.StackFrame(True) ' Method name
MessageBox.Show(tString & " " & s.GetMethod().Name)

HTH

Nigel Armstrong
 
How about the name of calling class?


Nigel Armstrong said:
Hi Nikolay

Try this for starters:

Dim tString As String = Me.GetType().Name ' Class name
Dim s As New System.Diagnostics.StackFrame(True) ' Method name
MessageBox.Show(tString & " " & s.GetMethod().Name)

HTH

Nigel Armstrong
 
Hi Nikolay

You could create a StackTrace for this:


Dim m As New System.Diagnostics.StackTrace
MessageBox.Show("trace " & m.ToString())

Note that this gives the complete call stack...

And one more thing - to get an ID, you could try something like this:

Dim sf As New System.Diagnostics.StackFrame
Dim s As String = Me.GetType.Name & sf.GetMethod().Name
MessageBox.Show("id: " & s.GetHashCode())

I'm not sure that this would be a good idea though...it's not exactly the
most performant way of getting an ID value.

HTH anyway

Nigel Armstrong
 
Thanks for your time Nigel

Nigel Armstrong said:
Hi Nikolay

You could create a StackTrace for this:


Dim m As New System.Diagnostics.StackTrace
MessageBox.Show("trace " & m.ToString())

Note that this gives the complete call stack...

And one more thing - to get an ID, you could try something like this:

Dim sf As New System.Diagnostics.StackFrame
Dim s As String = Me.GetType.Name & sf.GetMethod().Name
MessageBox.Show("id: " & s.GetHashCode())

I'm not sure that this would be a good idea though...it's not exactly the
most performant way of getting an ID value.

HTH anyway

Nigel Armstrong
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top