|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can reflection tell the base class of an object?Hey guys,
Are there functions in reflection that gives information about the base classes of an object? Thanks in advance -Steve Check out the Type class's GetBaseType method.
http://msdn2.microsoft.com/en-us/library/system.type_members.aspx Show quoteHide quote news:1162570961.222895.124290@m73g2000cwd.googlegroups.com... > Hey guys, > > Are there functions in reflection that gives information about the base > classes of an object? > > Thanks in advance > -Steve > <stkt***@yahoo.com> wrote in message
news:1162570961.222895.124290@m73g2000cwd.googlegroups.com... Here's an example:> Hey guys, > > Are there functions in reflection that gives information about the base > classes of an object? > > Thanks in advance > -Steve > Private Sub ShowInheritanceTree(ByVal Instance As Object) Dim t As Type = Instance.GetType() Dim n As Integer = 0 Dim tmp As Type = t Dim names As ArrayList = New ArrayList() While Not tmp Is GetType(Object) If tmp Is Nothing tmp = t.BaseType Else tmp = tmp.BaseType End If names.Add(tmp.Name) n += 1 End While Dim line As String Dim spaces As String For i As Integer = n - 1 To 0 Step -1 line = String.Empty If i < n - 1 spaces = StrDup(((n - 1) - i) * 4, " ") line = spaces & "|" & vbNewLine & spaces & "--- " End If line &= CStr(names(i)) Console.WriteLine(line) Next i End Sub This method goes up the inheritance tree looking for the base types of each class the current class inherits from then reverses the search to display each class from top-to-bottom. HTH, Mythran
Merge/Synchronize XML Files
[Regular Expression] (aaa AND bbb) OR (ccc AND ddd) Subclassing Disposing of Windows Forms don't show error windows Printer Ink Status Get machine user & password logon Deleting Values from an XML node? VB6 query format for comparing number value Prevent Date Enter before Current date |
|||||||||||||||||||||||