473,696 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetType within shared method

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(<nameof type>) < 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
4 4479
"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(<nameof type>) < 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.Get CurrentMethod() .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
> Any idea on how I can find it dynamically without having to write the
name of the type myself?


MethodBase.GetC urrentMethod(). 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
Hurrah! thanks for your help!

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


MethodBase.GetC urrentMethod(). 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
Hurrah! thanks for your help!

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** ********@TK2MSF TNGP14.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(<nameof type>) < 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.Get CurrentMethod() .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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3559
by: John Brock | last post by:
I have a base class with several derived classes (I'm writing in VB.NET). I want each derived class to have a unique class ID (a String), and I want the derived classes to inherit from the base class *Shared* methods which make use of the class ID. So I gave the base class a classID field, and then I gave the derived classes Shared constructors, which I used to set the classID field to the appropriate values for each derived class. But...
1
3216
by: hazz | last post by:
"Value cannot be null.\r\nParameter name: type" is the exception thrown after the CreateInstance method below. Type t = Type.GetType(GetConfigValue("PasswordProvider")); IPasswordProvider ppdr= (IPasswordProvider)Activator.CreateInstance(t); GetConfigValue DOES return the correct value from the config file - "namespace.DBPassword, namespace" It appears that Type.GetType is NOT finding the assembly whose name is the
9
7997
by: Yan Vinogradov | last post by:
Hi, Turns out it's possible to spoof another type with Object.GetType method. If you do this: namespace N { class C { public new Type GetType() { return (String.Empty.GetType()); }
6
19201
by: Jim Bancroft | last post by:
Hi everyone, I'm having some trouble with the code below. I receive a compile-time error on the second line saying "; expected": private static void myTestFunction(long myLong) { System.Data.SqlTypes.SqlInt32 myTestInt;
5
2263
by: Matthew | last post by:
I have a nice little Sub that saves data in a class "mySettings" to an XML file. I call it like so: Dim mySettings As mySettings = New mySettings mySettings.value1 = "someText" mySettings.value2 = "otherText" xmlSave("C:\folder\file.xml", mySettings) Here is the sub: Public Shared Sub xmlSave(ByVal path As String, ByVal config As
4
15104
by: Greg Burns | last post by:
What the difference between these two? System.Type.GetType("System.Int32") and GetType(Integer) Or more specifically, why does GetType(Integer) work, but not System.Type.GetType(Integer)? What namespace is the GetType function(?) part of?
4
7170
by: Materialised | last post by:
Hi All, I have a strange issue, and I am not sure if it is a error on my part, or a visual studio bug. I am using VS.Net 2003 Enterprise. I have 2 event handlers as follows: Public Shared Sub txtFace1_DoubleClick(ByVal sender As Object, ByVal e
6
1454
by: Paul | last post by:
I have two projects in one solution. One is called Frontier and holds all my base user controls, classes, etc. that are used over multiple applications. The second is my application project (OCFU) which holds the forms and code that the users run. I need to instantiate a new form only given the form's name in a string. In the calling form in the OCFU project I used the following code: Dim objNewForm As Object =...
4
5057
by: Pieter | last post by:
Hi, Using VB.NET 2005: When you use a Me.MyFunction to a Shared Method, you het the error "'Me' is valid only within an instance method.". Which is normal. But: Which keyword can you use instead of the "Me" to refer to a Shared Method in the same Class? Because without the "Me" you can't use the intellisense-stuff, and I don't like to go copy paste methods or remember there names :-)
0
8667
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8597
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
9012
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...
1
8880
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8853
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4357
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
4611
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3034
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
2319
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.