473,410 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

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


Nov 21 '05 #1
2 1048
> 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
Nov 21 '05 #2

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" <no@spam.please> 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


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
5
by: Christian Christmann | last post by:
Hi, I've a some classes which are all inherited from the same base class class_BASE; There's another class which holds some information and is "bound" to one of the inherited classes...
2
by: dsandor | last post by:
I have a class that is inherited by another class. Let say: public class vehicle { public string color { get ... set ... } }
3
by: Magnus | last post by:
i have a class which inherits from a base class class base1 { } class child1 : base1 { } how can I determine if child1 is of base1? gettype returns type of child1, but I need to know the...
3
by: Froefel | last post by:
I'm trying to modem a relationship with classes and I'm having trouble finding the correct design pattern. Maybe someone with more experience knows which pattern(s) I'm looking for. Here's an...
6
by: burningodzilla | last post by:
Hi all - I'm preparing to dive in to more complex application development using javascript, and among other things, I'm having a hard time wrapping my head around an issues regarding "inheritance"...
9
by: Mark Berry | last post by:
Hi, How can I determine whether an object is derived from another object? My specific example is that I have a CustomError class with several specific error types that derive from it...
12
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I have a class which "BiologySequence" which looks about like this. public class BiologySequence { private string _Sequence; public string Sequence {
7
by: joproulx | last post by:
Hi, I was wondering if there was a way with Reflection to find dynamically if an object was referencing indirectly another object. A simple example would be: Object1 | --Object2 |
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.