Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to programmatically obtain current class name

Posted on 2007-10-01
5
Medium Priority
?
290 Views
Last Modified: 2010-04-23
Hi guys,
For debugging purposes I would like to have a Debug.Print statement that I can place in any function/property/etc. to identify that class.method.

I know how to obtain method name 'Debug.Print (System.Reflection.MethodInfo.GetCurrentMethod.Name)' but I don't know how to obtain class/module name.

Thanks,
     Michael
0
Comment
Question by:gem56
  • 3
  • 2
5 Comments
 

Author Comment

by:gem56
ID: 19995916
Hi RedKelvin,
I tried the following but it didn't work:

        Dim ThisAssembly As Assembly = Assembly.GetExecutingAssembly()
        Dim TypeObj As Type
        For Each TypeObj In ThisAssembly.GetTypes()
            Console.WriteLine(TypeObj.Name)
        Next

I couldn't get help on GetExecutingAssembly either. Is the above solution for VB.NET?
0
 

Author Comment

by:gem56
ID: 19995935
I jumped the gun a bit. I modified the above example (as per below) and that gave me a whole bunch of information including the name of every module in my application.

        Dim ThisAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
        Dim TypeObj As Type
        For Each TypeObj In ThisAssembly.GetTypes()
            Debug.Print(TypeObj.Name)
        Next

My requirement is to obtain the name of the 'current' module.

/Michael
0
 
LVL 22

Accepted Solution

by:
RedKelvin earned 500 total points
ID: 19997359
Hi, yeah your code is the same, just a little more verbose, putting

Imports System.Reflection

at the top also would have worked

to get the current method name
Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod.Name())

to get the current module name
Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name)

Happy coding
0
 

Author Comment

by:gem56
ID: 19997404
That's exactly what I was after. Thanks a lot.
/Michael
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month20 days, 21 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question