"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Glen,
You have made from those classes objects, you should know in your program
what you instance.
You are not dealing with classes, only when you want to know the type
(class) of the object.
For what is gettype.
http://msdn.microsoft.com/library/de...ttypetopic.asp
I hope this helps,
Cor
To add a question regarding what you are doing, and in conjunction with the
good answer that Cor has posted:
You want to check in the base class whether or not the current instance is a
base class or derived from the base class? If this is true, I can't think
of a reason why you would ever want to check this inside of a base class.
Maybe you do have a good reason...but, since I don't know a solution
(without hardcoding each and every derived class' name and passing to
GetType()), what is the layout/setup of your code. I would like to know to
see what the real problem is to see if we can come to a better solution to
what you are doing...
If you really want to tell, here is a sample of your problem, and a way to
do it:
Public Class InternalMain
<STAThread()> _
Public Shared Sub Main()
Dim a As MyBaseClass = New MyBaseClass()
Dim b As MyDerivedClass = New MyDerivedClass()
Console.WriteLine("a.IsBaseClass(): " & a.IsBaseClass())
Console.WriteLine("b.IsBaseClass(): " & b.IsBaseClass())
End Sub
End Class
Public Class MyBaseClass
Public ReadOnly Property IsBaseClass() As Boolean
Get
' Return whether or not the current object is an instance
' of this class or a derived class.
Return Me.GetType() Is GetType(MyBaseClass)
End Get
End Property
End Class
Public Class MyDerivedClass
Inherits MyBaseClass
End Class
' The above code, when compiled as a console program, displays:
a.IsBaseClass(): True
b.IsBaseClass(): False
HTH :)
Mythran