We help IT Professionals succeed at work.

How to programmatically obtain current class name

gem56
gem56 asked
on
457 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
Comment
Watch Question

Author

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?

Author

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
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
That's exactly what I was after. Thanks a lot.
/Michael
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.