473,396 Members | 1,853 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,396 software developers and data experts.

class types in vb.net

I am a Delphi programmer switching to vb.net. In Delphi you could
define a metaclasstype like

type MetaClassName = class of TSomeClass;

and you could use this type as a function result. This way you could
get as a function result the type of a class instead of an instance of
this class.

My question is, is there an equivalent in vb.net? And if so, what is
the syntax.

------
Marius

Dec 18 '06 #1
4 1330
Something like this?
Public Function Foo(ByVal theClass As Object) As Type
Return theClass.GetType()
End Function
Dec 18 '06 #2
It would be:

Dim MetaClassName As Type = Type.GetType(TSomeClass)

If you had a variable that was an instance of something then it would be:

Dim MetaClassName As Type = SomeInstance.GetType()
"Marius" <ma**********@gmail.comwrote in message
news:11**********************@n67g2000cwd.googlegr oups.com...
>I am a Delphi programmer switching to vb.net. In Delphi you could
define a metaclasstype like

type MetaClassName = class of TSomeClass;

and you could use this type as a function result. This way you could
get as a function result the type of a class instead of an instance of
this class.

My question is, is there an equivalent in vb.net? And if so, what is
the syntax.

------
Marius

Dec 18 '06 #3
Marius,
In addition to the other comments:

Consider using:
type MetaClassName = class of TSomeClass;
Dim MetaClassName As Type = GetType(TSomeClass)

Be mindful of the GetType keyword, and the Type.GetType function.

The GetType keyword accepts a type identifier & will cause a compile error
if you give a non-existent type.

Dim MetaClassName As Type = GetType(TSomeClass)

The Type.GetType function accepts a string & will cause a runtime error if
you give it a non-existent type. Generally its safest to give a qualified
name to Type.GetType that includes the namespace along with the assembly.

Dim MetaClassName As Type = GetType("SomeNamespace.TSomeClass,
SomeAssembly")
For types within my assembly or assemblies that I know I have explicitly
referenced I will use the GetType keyword so as to ensure compile time
errors.

For types that I want to dynamically load, for example plugins listed in the
app/web config, I will use the Type.GetType function.

--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Marius" <ma**********@gmail.comwrote in message
news:11**********************@n67g2000cwd.googlegr oups.com...
>I am a Delphi programmer switching to vb.net. In Delphi you could
define a metaclasstype like

type MetaClassName = class of TSomeClass;

and you could use this type as a function result. This way you could
get as a function result the type of a class instead of an instance of
this class.

My question is, is there an equivalent in vb.net? And if so, what is
the syntax.

------
Marius
Dec 18 '06 #4
"Marius" <ma**********@gmail.comschrieb:
>I am a Delphi programmer switching to vb.net. In Delphi you could
define a metaclasstype like

type MetaClassName = class of TSomeClass;

and you could use this type as a function result. This way you could
get as a function result the type of a class instead of an instance of
this class.

My question is, is there an equivalent in vb.net? And if so, what is
the syntax.
Check out the 'System.Type' class, its members and the 'GetType' statement.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Dec 18 '06 #5

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

Similar topics

5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
13
by: cgough | last post by:
My true programming language is C++. I am at best a VB6 hacker that is just getting into VB.NET. I have a quick question about when to new and when not to new. Consider the following 2 classes....
5
by: Rob | last post by:
In many articles related to VB.net the word "class" is used... How many meanings are there to this word ? "possible to derived a class from another" "forms are full-fledged classes" "base...
38
by: looping | last post by:
For Python developers around. >From Python 2.5 doc: The list of base classes in a class definition can now be empty. As an example, this is now legal: class C(): pass nice but why this...
5
by: edd | last post by:
Hello all, Please consider: template<typename Tclass my_class; template<class my_class<int> { //... };
37
by: JohnGoogle | last post by:
Hi, Newbie question... After a recent article in VSJ I had a go at implementing a Fraction class to aid my understanding of operator overloading. After a previous message someone suggested...
70
by: garyusenet | last post by:
I'm using an example piece of code: - namespace Wintellect.Interop.Sound{ using System; using System.Runtime.InteropServices; using System.ComponentModel; sealed class Sound{ public static...
11
by: garyusenet | last post by:
I have 'cli via c# on order', and in the mean time am reading 'Pro C# 2005 and the .NET platform' (Andrew Troelson). I'm just reading about the 'five types defined in the CTS'. Specifically Struct....
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
55
by: tonytech08 | last post by:
How valuable is it that class objects behave like built-in types? I appears that the whole "constructor doesn't return a value because they are called by the compiler" thing is to enable...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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
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.