473,508 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get class name and class method

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
Nov 21 '05 #1
4 2053
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

"Nikolay Petrov" wrote:
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

Nov 21 '05 #2
How about the name of calling class?
"Nigel Armstrong" <Ni************@discussions.microsoft.com> wrote in
message news:DC**********************************@microsof t.com...
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

"Nikolay Petrov" wrote:
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

Nov 21 '05 #3
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

"Nikolay Petrov" wrote:
How about the name of calling class?
"Nigel Armstrong" <Ni************@discussions.microsoft.com> wrote in
message news:DC**********************************@microsof t.com...
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

"Nikolay Petrov" wrote:
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


Nov 21 '05 #4
Thanks for your time Nigel

"Nigel Armstrong" <Ni************@discussions.microsoft.com> wrote in
message news:87**********************************@microsof t.com...
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

"Nikolay Petrov" wrote:
How about the name of calling class?
"Nigel Armstrong" <Ni************@discussions.microsoft.com> wrote in
message news:DC**********************************@microsof t.com...
> 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
>
> "Nikolay Petrov" wrote:
>
>> 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
>>
>>
>>


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
1914
by: syd | last post by:
In my project, I've got dozens of similar classes with hundreds of description variables in each. In my illustrative example below, I have a Library class that contains a list of Nation classes. ...
18
6934
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
5
14407
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
5
3140
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
2
1484
by: lcaamano | last post by:
We have a tracing decorator that automatically logs enter/exits to/from functions and methods and it also figures out by itself the function call arguments values and the class or module the...
4
3287
by: Pedro Werneck | last post by:
Hi all I noticed something strange here while explaining decorators to someone. Not any real use code, but I think it's worth mentioning. When I access a class attribute, on a class with a...
2
1595
by: BBM | last post by:
I may be putting too fine a point on this, but I'd like to be able to know the class name of a shared method from within the method. BTW, the shared method is in a "MustInherit" class. So it...
0
2812
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
21
2333
by: John Henry | last post by:
Hi list, I have a need to create class methods on the fly. For example, if I do: class Dummy: def __init__(self): exec '''def method_dynamic(self):\n\treturn self.method_static("it's...
11
2419
by: TinaJones095 | last post by:
Hello I am going to give a program that I have done, but I have to modifiy it, but I need help okay can you help ? Here the program I need help to straighten up below: the Java error is right at...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.