By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

Getting Namespace and class name

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Don" <un*****@oblivion.com> schrieb:
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().* '.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #2

P: n/a
"Don" <un*****@oblivion.com> wrote in message
news:Rd8ed.181520$a41.10875@pd7tw2no...
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.
Nov 21 '05 #3

P: n/a
Don
"Imran Koradia" <no****@microsoft.com> wrote in message
news:Ov****************@tk2msftngp13.phx.gbl...
"Don" <un*****@oblivion.com> wrote in message
news:Rd8ed.181520$a41.10875@pd7tw2no...

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


Sorry, I forgot to mention that this, too, needs to be executable from a
shared method.

- Don
Nov 21 '05 #4

P: n/a
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.
"Don" <un*****@oblivion.com> wrote in message
news:dN8ed.7166$kN2.2540@pd7tw3no...
"Imran Koradia" <no****@microsoft.com> wrote in message
news:Ov****************@tk2msftngp13.phx.gbl...
"Don" <un*****@oblivion.com> wrote in message
news:Rd8ed.181520$a41.10875@pd7tw2no...

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

code?

Me.GetType().Namespace


Sorry, I forgot to mention that this, too, needs to be executable from a
shared method.

- Don

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.