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

GetType within shared method

P: n/a
Hi there,

I'm trying to find the quickest way to get a type object of the current
class within any part of the class. For example,

Me.GetType < This works fine within an instance method but not in a
shared method

GetType(<nameoftype>) < This works fine but defeats the object

Any idea on how I can find it dynamically without having to write the
name of the type myself?

Cheers in advance.

Nick.
Feb 9 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Nick Pateman" <a@a.com> schrieb:
I'm trying to find the quickest way to get a type object of the current
class within any part of the class. For example,

Me.GetType < This works fine within an instance method but not in a
shared method

GetType(<nameoftype>) < This works fine but defeats the object

Any idea on how I can find it dynamically without having to write the
name of the type myself?


Try 'MethodBase.GetCurrentMethod().DeclaringType'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 9 '06 #2

P: n/a
> Any idea on how I can find it dynamically without having to write the
name of the type myself?


MethodBase.GetCurrentMethod().DeclaringType
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 9 '06 #3

P: n/a
Hurrah! thanks for your help!

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Any idea on how I can find it dynamically without having to write the
name of the type myself?


MethodBase.GetCurrentMethod().DeclaringType
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Feb 9 '06 #4

P: n/a
Hurrah! thanks for your help!

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
"Nick Pateman" <a@a.com> schrieb:
I'm trying to find the quickest way to get a type object of the
current class within any part of the class. For example,

Me.GetType < This works fine within an instance method but not in a
shared method

GetType(<nameoftype>) < This works fine but defeats the object

Any idea on how I can find it dynamically without having to write the
name of the type myself?


Try 'MethodBase.GetCurrentMethod().DeclaringType'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.