Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to find all base classes of any type in .Net

Total Hit ( 3004)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The following code shows how to print all base classes for a specified object.

Click here to copy the following block
Function PrintBaseClasses(ByVal obj As Object)
  Dim t As System.Type
  t = obj.GetType

  Do While Not t Is Nothing
    Debug.Write(t.Name)
    t = t.BaseType
    If Not t Is Nothing Then
      Debug.Write("->")
    End If
  Loop
End Function

You can call this function as below

Click here to copy the following block
Dim ex As New OverflowException
PrintBaseClasses(ex)

Output

OverflowException->ArithmeticException->SystemException->Exception->Object

You can modify the PrintBaseClasses routine to make it more useful so you can check any object to find out its base class.

Click here to copy the following block
Function IsTypeOf(ByVal obj As Object, ByVal TypeName As String) As Boolean
  Dim t As System.Type
  t = obj.GetType

  Do While Not t Is Nothing
    If t.Name.ToLower = TypeName.ToLower Then
      Return True
      Exit Function
    End If
    t = t.BaseType
  Loop
  Return False
End Function

You can call the above routine as shown below

Click here to copy the following block
Dim ex As New OverflowException

If IsTypeOf(ex, "Exception")=True Then
   Debug.Write("Yes this object is type of [Exception]")
Else
   Debug.Write("No this object is not type of [Exception]")
End If

Output

Yes this object is type of [Exception]


Submitted By : Jojo Desuja  (Member Since : 8/10/2004 10:56:17 PM)

Job Description : The King of Night....... Love to do programming specially night time....
View all (22) submissions by this author  (Birth Date : )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.