473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Getting Namespace and class name

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
4 1407
"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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Matt Mastracci | last post by:
It seems like the C# compile can't resolve the difference between a namespace and a class in a situation that is clearly unambiguous. Note that it sees the namespace "C" before the class "C". I...
5
by: David Rasmussen | last post by:
If I have a string that contains the name of a function, can I call it? As in: def someFunction(): print "Hello" s = "someFunction" s() # I know this is wrong, but you get the idea... ...
6
by: Robert Warnestam | last post by:
I've two class libraries, where one is referencing the other. The first library looks like this; (assembly name and root name space is set to Codab.Parser) namespace Codab.Parser { public class...
4
by: Richard | last post by:
Hi All, I am using Visual C++ .Net to create a windows forms application and I am getting the following errors when I do a MessageBox::Show in my Form1.cpp file: Form1.cpp(19): error C2653:...
2
by: Danny Gagne | last post by:
I'm currently working an .net application (I can use 1.1 or 2.0 if needed) that needs to read a wsdl file and generate another piece of code that can use it. I'm encountering a problem where I...
9
by: Brian | last post by:
So I have this: double x = .25; double y = .5; double z = .25; double probability; int index; while(index < 30) {
2
by: Andrés G. Aragoneses [ knocte ] | last post by:
Hello. I am creating a class that is derived from one that comes from an auto-generated code from a webservice reference. The base class has certain XML attributes that are inherited in my...
9
by: Mark Olbert | last post by:
I'm trying to serialize (using XmlSerializer.Serialize) a class that I generated from an XSD schema using XSD.EXE /c. The problem I'm running into is that the root element needs to be unqualified,...
5
by: tshad | last post by:
I have the following class in my VS 2008 project that has a namespace of MyFunctions. ********************************* Imports System Imports System.Text.RegularExpressions Namespace...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.