Getting Namespace and class name

D

Don

Two questions:


1. Is there a way to get the current namespace name as a string via code?


2. Is there a way to get the name of the class a piece of shared/static code
is in?

i.e.

Public Class MyClass
Public Shared Function ClassName as String
Return Me.Name ' <-- This only works for instances, but I need
something like
' this for shared classes.
End Function
End Class


- Don
 
H

Herfried K. Wagner [MVP]

Don said:
1. Is there a way to get the current namespace name as a string via code?


2. Is there a way to get the name of the class a piece of shared/static
code
is in?

'System.Reflection.MethodBase.GetCurrentMethod().*'.
 
I

Imran Koradia

Don said:
Two questions:


1. Is there a way to get the current namespace name as a string via code?
Me.GetType().Namespace



2. Is there a way to get the name of the class a piece of shared/static code
is in?

i.e.

Public Class MyClass
Public Shared Function ClassName as String
Return Me.Name ' <-- This only works for instances, but I need
something like
' this for shared classes.
End Function
End Class
Already answered by Herfried..


hope that helps..
Imran.
 
I

Imran Koradia

Dim oBase As System.Reflection.MethodBase = _
System.Reflection.MethodBase.GetCurrentMethod()

Dim oType As Type = oBase.ReflectedType

' Namespace of the class to which the method belongs
MessageBox.Show(oType.Namespace)

'Name of Class to which the method belongs
MessageBox.Show(oType.Name)


hope that helps..
Imran.
 

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

Top