Getting Namespace and class name

  • Thread starter Thread starter Don
  • Start date Start date
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
 
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().*'.
 
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.
 
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.
 
Back
Top