|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
class types in vb.netI 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 Something like this?
Public Function Foo(ByVal theClass As Object) As Type Return theClass.GetType() End Function 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() Show quoteHide quote "Marius" <mariusdev***@gmail.com> wrote in message news:1166436292.766818.170830@n67g2000cwd.googlegroups.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 > 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. -- Show quoteHide quoteHope this helps Jay B. Harlow ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Marius" <mariusdev***@gmail.com> wrote in message news:1166436292.766818.170830@n67g2000cwd.googlegroups.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 > "Marius" <mariusdev***@gmail.com> schrieb: Check out the 'System.Type' class, its members and the 'GetType' statement.>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. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> |
|||||||||||||||||||||||