How to programmatically obtain current class name

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
gem56Asked:
Who is Participating?
 
RedKelvinConnect With a Mentor Commented:
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
 
gem56Author Commented:
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
 
gem56Author Commented:
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
 
gem56Author Commented:
That's exactly what I was after. Thanks a lot.
/Michael
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.