PC Review


Reply
Thread Tools Rate Thread

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

 
 
Joergen Bech
Guest
Posts: n/a
 
      19th Aug 2005

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




 
Reply With Quote
 
 
 
 
Dragon
Guest
Posts: n/a
 
      19th Aug 2005
> 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?


A MUCH shorter way:

TypeOf o Is System.Windows.Forms.Control

8=]

Roman


 
Reply With Quote
 
Joergen Bech
Guest
Posts: n/a
 
      19th Aug 2005

Thanks. I bow my head in shame. At least I knew that there was
something I did not know. Small comfort.

/JB

On Fri, 19 Aug 2005 15:29:27 +0400, "Dragon" <(E-Mail Removed)> wrote:

>> 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?

>
>A MUCH shorter way:
>
>TypeOf o Is System.Windows.Forms.Control
>
>8=]
>
>Roman
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a base class method return an object of an inherited class typ Ethan Strauss Microsoft C# .NET 12 12th Jan 2008 12:41 AM
Determine type of inherited class Magnus Microsoft C# .NET 3 24th Aug 2006 02:56 PM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting Microsoft ASP .NET 0 29th Dec 2003 07:08 AM
Converting type from base class to inherited class Nick Foster Microsoft VB .NET 5 4th Dec 2003 10:44 PM
Determine the object (parent?) from an inherited class. dsandor Microsoft C# .NET 2 20th Aug 2003 02:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:51 PM.