How to determine if an object class is indirectly inherited from a specific type?




I have written the following snippet (which works), but is there a
more "correct" way to do this? Any way of getting rid of the
loop?

TIA,

Joergen Bech

---snip---

Private Function IsSystemWindowsFormsControl(ByVal o As
Object) As Boolean
If o Is Nothing Then
Return False
Else
Return ObjectInheritsFromClass(o,
GetType(System.Windows.Forms.Control))
End If
End Function

Private Function ObjectInheritsFromClass(ByVal ctrl As Object,
ByVal ObjectType As Type) As Boolean
Dim ct As Type = ctrl.GetType
Do While Not ct Is Nothing
If ct.Equals(ObjectType) Then
Return True
Else
ct = ct.BaseType
End If
Loop
Return False
End Function




.



Relevant Pages

  • Re: MKDir not working
    ... Public Sub MkDirs ... first argument of the Split function in the active loop statement; ... track and return a Boolean status from the function. ... MkDirs = MkDirs + Err.Number ...
    (microsoft.public.vb.general.discussion)
  • Re: GNAT compiler switches and optimization
    ... allocating and freeing arrays, the the effects ... But I imagined allocation is just what is happening all the time ... type LIST is array of BOOLEAN; ... 2000 loop ...
    (comp.lang.ada)
  • Re: Create a file larger than 3 gb
    ... DWORD dwBytesWrite, dwSize; ... EVER compare a boolean to a literal truth value! ... and do it OUTSIDE the loop, since there is no reason to zero it a second, ... but what are you comparing it to? ...
    (microsoft.public.vc.mfc)
  • Re: Topological Sort Help
    ... PACKAGE BODY Digraphs IS ... RETURN Digraph IS ... WHILE NOT End_Of_FileLOOP ... Value: OUT Boolean) IS ...
    (comp.lang.ada)
  • Re: WBemScripting.SWbemSink and Do Loop - Explained
    ... Is the Subroutine SINK_OnObjectReady being called within the loop? ... In VBScript, boolean True converts to integer -1, while boolean False ... And therefore the function of the Loop is to merely keep the script ...
    (microsoft.public.scripting.vbscript)