473,734 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how-to get the name of the current project and class



Hi Everyone--

Please help.

How can one get the name of the current project and the current class?

This is the situation.

Suppose there is a project called "P1".

Now, suppose that in the P1 project there is a class called "C1".

Now, suppose that in the C1 class there is a method called "M1".

Now, suppose that code is executing in M1 and one wants to grab the name of
current the project and the name of the current class and read them into
variables.

How can this be done?

(As a bonus, it would also be GREAT if one could grab the name of the
current method too, but I was once told this cannot be done; but, I don't
believe it.)

Any help is appreciated.

(Please note that I am looking in the help files under Reflection, but I
have not found it yet.)

Thank you.

--Mark

Nov 17 '05 #1
15 1989
Hi Mark,

You can find out about the routine that you're in as well as all its
callers.

Public Function MeAndMyCaller As String
Dim CurrentStack As New System.Diagnost ics.StackTrace( )
Dim Myself As String = CurrentStack.Ge tFrame(0).GetMe thod.Name
Dim MyCaller As String = CurrentStack.Ge tFrame(1).GetMe thod.Name
Return "In " & Myself & vbCrLf & "Called by " & MyCaller
End Function

This can be very handy if you want a generalised error routine because it
can get the name of the caller (which would be where the error occurred).

Regards,
Fergus
Nov 17 '05 #2


Herfried--

Thank you for the reply.

Regarding getting the project name...

Unfortunately, that call yields a lot of other "junk" that is not needed in
this case.

All that is needed is the project name itself.
That is, it is good, but it is TOO much.

Note the following...
...this...

Response.Write( "System.Reflect ion.Assembly.Ge tExecutingAssem bly.FullName =
" & System.Reflecti on.Assembly.Get ExecutingAssemb ly.FullName)

....yields...

System.Reflecti on.Assembly.Get ExecutingAssemb ly.FullName =
TestVBGeneral20 030818, Version=1.0.134 2.16137, Culture=neutral ,
PublicKeyToken= null

....and this...

Response.Write( "Me.GetType.Ass embly.GetExecut ingAssembly.Ful lName() = " &
Me.GetType.Asse mbly.GetExecuti ngAssembly.Full Name())

....yields...

Me.GetType.Asse mbly.GetExecuti ngAssembly.Full Name() =
TestVBGeneral20 030818, Version=1.0.134 2.16137, Culture=neutral ,
PublicKeyToken= null
....any ideas how I can get JUST the project name, (of course, without
having to parse the string)?


"Herfried K. Wagner [MVP]" <hi*******@m.ac tivevb.de> wrote in message
news:ez******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

"Mark Kamoski" <mk******@yahoo .com> schrieb:
Now, suppose that in the P1 project there is a class called "C1".
You can get the name of the assembly:

\\\
MsgBox(System.R eflection.Assem bly.GetExecutin gAssembly.FullN ame)
///
(As a bonus, it would also be GREAT if one could grab the name of the
current method too, but I was once told this cannot be done; but, I don't
believe it.)


\\\
MsgBox(System.R eflection.Metho dBase.GetCurren tMethod().Name)
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 17 '05 #3
"MS News (MS ILM)" <sq***********@ hotmail.com> schrieb:
CType(System.R eflection.Metho dBase.GetCurren tMethod(), MethodInfo)


Why not use 'DirectCast' instead of 'CType'?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 17 '05 #4
you are right

"Herfried K. Wagner [MVP]" <hi*******@m.ac tivevb.de> wrote in message
news:OZ******** ******@TK2MSFTN GP09.phx.gbl...
"MS News (MS ILM)" <sq***********@ hotmail.com> schrieb:
CType(System.R eflection.Metho dBase.GetCurren tMethod(), MethodInfo)


Why not use 'DirectCast' instead of 'CType'?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 17 '05 #5
Get name of project

system.Reflecti on.Assembly.Get ExecutingAssemb ly.FullName.Spl it(",",3)(0)

"Mark Kamoski" <mk******@yahoo .com> wrote in message news:uR******** ********@TK2MSF TNGP10.phx.gbl. ..


Herfried--

Thank you for the reply.

Regarding getting the project name...

Unfortunately, that call yields a lot of other "junk" that is not needed in
this case.

All that is needed is the project name itself.


That is, it is good, but it is TOO much.

Note the following...


..this...

Response.Write( "System.Reflect ion.Assembly.Ge tExecutingAssem bly.FullName =
" & System.Reflecti on.Assembly.Get ExecutingAssemb ly.FullName)

...yields...

System.Reflecti on.Assembly.Get ExecutingAssemb ly.FullName =
TestVBGeneral20 030818, Version=1.0.134 2.16137, Culture=neutral ,
PublicKeyToken= null

...and this...

Response.Write( "Me.GetType.Ass embly.GetExecut ingAssembly.Ful lName() = " &
Me.GetType.Asse mbly.GetExecuti ngAssembly.Full Name())

...yields...

Me.GetType.Asse mbly.GetExecuti ngAssembly.Full Name() =
TestVBGeneral20 030818, Version=1.0.134 2.16137, Culture=neutral ,
PublicKeyToken= null


...any ideas how I can get JUST the project name, (of course, without
having to parse the string)?






"Herfried K. Wagner [MVP]" <hi*******@m.ac tivevb.de> wrote in message
news:ez******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

"Mark Kamoski" <mk******@yahoo .com> schrieb:
Now, suppose that in the P1 project there is a class called "C1".


You can get the name of the assembly:

\\\
MsgBox(System.R eflection.Assem bly.GetExecutin gAssembly.FullN ame)
///
(As a bonus, it would also be GREAT if one could grab the name of the
current method too, but I was once told this cannot be done; but, I don't
believe it.)


\\\
MsgBox(System.R eflection.Metho dBase.GetCurren tMethod().Name)
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 17 '05 #6

Everyone--

OK, thank you so much for your help.

All set except for one small thing.

The call that I am using to get the class name returns "WebForm1_a spx"
rather than "WebForm1".

I do NOT want to have to parse the string.

Is there a way to do this in one call?

Please advise.

Below is what I am using.
'Code...

'.....

'This returns the project name.

Response.Write( "ProjectNam e =
Me.GetType.Asse mbly.GetExecuti ngAssembly().Ge tName().Name = " &
Me.GetType.Asse mbly.GetExecuti ngAssembly().Ge tName().Name)

'This returns the class name, plus a little more. That is, it returns
"WebForm1_a spx" instead of "WebForm1".

Response.Write( "ClassName = Me.GetType.Name = " & Me.GetType().Na me)

'This returns the method name.

Response.Write( "MethodName =
System.Reflecti on.MethodBase.G etCurrentMethod ().Name = " &
System.Reflecti on.MethodBase.G etCurrentMethod ().Name)

'.....

'Output...

'ProjectName = Me.GetType.Asse mbly.GetExecuti ngAssembly().Ge tName().Name =
TestVBGeneral20 030818

'ClassName = Me.GetType.Name = WebForm1_aspx

'MethodName = System.Reflecti on.MethodBase.G etCurrentMethod ().Name =
btnTestGetTypeO fMe01_Click()


"Mark Kamoski" <mk******@yahoo .com> wrote in message
news:uU******** ******@TK2MSFTN GP12.phx.gbl...
Hi Everyone--

Please help.

How can one get the name of the current project and the current class?

This is the situation.

Suppose there is a project called "P1".

Now, suppose that in the P1 project there is a class called "C1".

Now, suppose that in the C1 class there is a method called "M1".

Now, suppose that code is executing in M1 and one wants to grab the name of
current the project and the name of the current class and read them into
variables.

How can this be done?

(As a bonus, it would also be GREAT if one could grab the name of the
current method too, but I was once told this cannot be done; but, I don't
believe it.)

Any help is appreciated.

(Please note that I am looking in the help files under Reflection, but I
have not found it yet.)

Thank you.

--Mark
Nov 17 '05 #7

Hi MS News--

It seems that this works too...
Response.Write( "ProjectNam e =
Me.GetType.Asse mbly.GetExecuti ngAssembly().Ge tName().Name = " &
Me.GetType.Asse mbly.GetExecuti ngAssembly().Ge tName().Name)

Thank you.

--Mark

"MS News (MS ILM)" <sq***********@ hotmail.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
Get name of project

system.Reflecti on.Assembly.Get ExecutingAssemb ly.FullName.Spl it(",",3)(0)

"Mark Kamoski" <mk******@yahoo .com> wrote in message
news:uR******** ********@TK2MSF TNGP10.phx.gbl. ..


Herfried--

Thank you for the reply.

Regarding getting the project name...

Unfortunately, that call yields a lot of other "junk" that is not needed in this case.

All that is needed is the project name itself.
That is, it is good, but it is TOO much.

Note the following...
..this...

Response.Write( "System.Reflect ion.Assembly.Ge tExecutingAssem bly.FullName = " & System.Reflecti on.Assembly.Get ExecutingAssemb ly.FullName)

...yields...

System.Reflecti on.Assembly.Get ExecutingAssemb ly.FullName =
TestVBGeneral20 030818, Version=1.0.134 2.16137, Culture=neutral ,
PublicKeyToken= null

...and this...

Response.Write( "Me.GetType.Ass embly.GetExecut ingAssembly.Ful lName() = " &
Me.GetType.Asse mbly.GetExecuti ngAssembly.Full Name())

...yields...

Me.GetType.Asse mbly.GetExecuti ngAssembly.Full Name() =
TestVBGeneral20 030818, Version=1.0.134 2.16137, Culture=neutral ,
PublicKeyToken= null
...any ideas how I can get JUST the project name, (of course, without
having to parse the string)?


"Herfried K. Wagner [MVP]" <hi*******@m.ac tivevb.de> wrote in message
news:ez******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

"Mark Kamoski" <mk******@yahoo .com> schrieb:
Now, suppose that in the P1 project there is a class called "C1".


You can get the name of the assembly:

\\\
MsgBox(System.R eflection.Assem bly.GetExecutin gAssembly.FullN ame)
///
(As a bonus, it would also be GREAT if one could grab the name of the
current method too, but I was once told this cannot be done; but, I don't believe it.)


\\\
MsgBox(System.R eflection.Metho dBase.GetCurren tMethod().Name)
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 17 '05 #8
Get class name
system.Reflecti on.MethodBase.G etCurrentMethod .DeclaringType( ).ToString()



"Mark Kamoski" <mk******@yahoo .com> wrote in message news:uR******** ********@TK2MSF TNGP10.phx.gbl. ..


Herfried--

Thank you for the reply.

Regarding getting the project name...

Unfortunately, that call yields a lot of other "junk" that is not needed in
this case.

All that is needed is the project name itself.


That is, it is good, but it is TOO much.

Note the following...


..this...

Response.Write( "System.Reflect ion.Assembly.Ge tExecutingAssem bly.FullName =
" & System.Reflecti on.Assembly.Get ExecutingAssemb ly.FullName)

...yields...

System.Reflecti on.Assembly.Get ExecutingAssemb ly.FullName =
TestVBGeneral20 030818, Version=1.0.134 2.16137, Culture=neutral ,
PublicKeyToken= null

...and this...

Response.Write( "Me.GetType.Ass embly.GetExecut ingAssembly.Ful lName() = " &
Me.GetType.Asse mbly.GetExecuti ngAssembly.Full Name())

...yields...

Me.GetType.Asse mbly.GetExecuti ngAssembly.Full Name() =
TestVBGeneral20 030818, Version=1.0.134 2.16137, Culture=neutral ,
PublicKeyToken= null


...any ideas how I can get JUST the project name, (of course, without
having to parse the string)?






"Herfried K. Wagner [MVP]" <hi*******@m.ac tivevb.de> wrote in message
news:ez******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

"Mark Kamoski" <mk******@yahoo .com> schrieb:
Now, suppose that in the P1 project there is a class called "C1".


You can get the name of the assembly:

\\\
MsgBox(System.R eflection.Assem bly.GetExecutin gAssembly.FullN ame)
///
(As a bonus, it would also be GREAT if one could grab the name of the
current method too, but I was once told this cannot be done; but, I don't
believe it.)


\\\
MsgBox(System.R eflection.Metho dBase.GetCurren tMethod().Name)
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 17 '05 #9
Me.GetType().To String().Split( CType("_", Char))(0).ToStr ing()
"Mark Kamoski" <mk******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..

Everyone--

OK, thank you so much for your help.

All set except for one small thing.

The call that I am using to get the class name returns "WebForm1_a spx"
rather than "WebForm1".

I do NOT want to have to parse the string.

Is there a way to do this in one call?

Please advise.

Below is what I am using.
'Code...

'.....

'This returns the project name.

Response.Write( "ProjectNam e =
Me.GetType.Asse mbly.GetExecuti ngAssembly().Ge tName().Name = " &
Me.GetType.Asse mbly.GetExecuti ngAssembly().Ge tName().Name)

'This returns the class name, plus a little more. That is, it returns
"WebForm1_a spx" instead of "WebForm1".

Response.Write( "ClassName = Me.GetType.Name = " & Me.GetType().Na me)

'This returns the method name.

Response.Write( "MethodName =
System.Reflecti on.MethodBase.G etCurrentMethod ().Name = " &
System.Reflecti on.MethodBase.G etCurrentMethod ().Name)

'.....

'Output...

'ProjectName = Me.GetType.Asse mbly.GetExecuti ngAssembly().Ge tName().Name =
TestVBGeneral20 030818

'ClassName = Me.GetType.Name = WebForm1_aspx

'MethodName = System.Reflecti on.MethodBase.G etCurrentMethod ().Name =
btnTestGetTypeO fMe01_Click()


"Mark Kamoski" <mk******@yahoo .com> wrote in message
news:uU******** ******@TK2MSFTN GP12.phx.gbl...
Hi Everyone--

Please help.

How can one get the name of the current project and the current class?

This is the situation.

Suppose there is a project called "P1".

Now, suppose that in the P1 project there is a class called "C1".

Now, suppose that in the C1 class there is a method called "M1".

Now, suppose that code is executing in M1 and one wants to grab the name of current the project and the name of the current class and read them into
variables.

How can this be done?

(As a bonus, it would also be GREAT if one could grab the name of the
current method too, but I was once told this cannot be done; but, I don't
believe it.)

Any help is appreciated.

(Please note that I am looking in the help files under Reflection, but I
have not found it yet.)

Thank you.

--Mark

Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2982
by: Tom Szabo | last post by:
Just wandering how can you close a browser remotely. In some web applications the browser closes or refreshes periodically. How is that done and how can it be done through PHP? TIA, Tom
15
16331
by: Reid Nichol | last post by:
Hello, I was wondering if I could control how many bytes are in an int and the byte order. In C/C++ I can use int32 but how do I do this in python? How can I control byte order?
0
1825
by: v I n O | last post by:
hI Geeks Please do let me know how do i find how many instances sql server running on the single machine. or in the n/w my objective should with help of C#/vb.net
4
2027
by: James Salisbury | last post by:
Hi, I was checking my parent's website salisbury.cabrera.net on google by entering villa rent spain cabrera I can see the required site, ranked at 4, but I am concerend by the return at 1 and 5 in the list. Any ideas why somone else may be using the text from my site, and how can I make an abuse report? Thanks
2
2583
by: Frances Del Rio | last post by:
http://www.emol.com/especiales/cocina_chilena/comida.asp this page is so neat (goes in pop-up..) how was this done? how do you give a layer (or div, I guess) a semi-transparency so you can still see img under it? (and how do you do the scroll for the div?) I know HTML very well, I also CSS and JavaScript, but am a bit mystified here... PLEASE respond by e-mail, fdr58@yahoo.com, my access to usenet is very limited.. thank you..
4
1982
by: | last post by:
Developing, building, and testing. How do it the best? Learning from the world leader - Microsoft I'm very interested in how the developing/build/testing workflow @ Microsoft looks like. I think Microsoft as world leader in software developing business must have a very good workflow. Does anyone know how the development flow @ Microsoft looks like?
4
2385
by: Supra | last post by:
in vb6 listbox1.remove item 5 how will i do in vb.net? regards
7
2579
by: anushhprabu | last post by:
#define q(k)main(){ return!puts(#k"\nPRABUq("#k")");} q(#define q(k)main(){return!puts(#k"\nq("#k")");}) guys i'm working on this code.. i got it fromnet.. how this is working.. anyone pls.. it is printing the same content on screen.. how ya.. how it is.. how how how?? please...................
0
1986
by: candra | last post by:
Learn What Hackers Know? -General Hacking Information -Password Security -Scanning, Fingerprinting And Similar Techniques -How Hackers Attack Numerous Internet Services -How Hackers Attack Web Servers, Cgis, PHP, ASP, Etc -How Hackers Attack IRC, Instant Messaging, And Multiplayer Games -Vulnerabilities Found In Platforms With Smaller Market Share -How Hackers Attack Novell And Networks
2
1616
by: belred | last post by:
i just read this blog about how many objects (types) are loaded for a hello world program in C#. http://blogs.msdn.com/abhinaba/archive/2008/09/15/how-many-types-are-loaded-for-hello-world.aspx how can you find out how many are loaded for a python program: print 'hello'
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.