473,396 Members | 1,838 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,396 software developers and data experts.

Finding subclasses

MR
I'm hoping that someone here will be able to direct me to some litrature on
how to get a list of a classes subclasses. I.e. need the inherited class to
know about subclasses that are inherited form it.

I guess that I'll have to use reflection but I can't find any examples on
MSDN.

Thanks in advance,
Mark
Nov 16 '05 #1
2 4393
MR <MR@discussions.microsoft.com> wrote:
I'm hoping that someone here will be able to direct me to some litrature on
how to get a list of a classes subclasses. I.e. need the inherited class to
know about subclasses that are inherited form it.

I guess that I'll have to use reflection but I can't find any examples on
MSDN.


You can only look through assemblies to find all subclasses - if you
don't know all the assemblies that might contain subclasses, you can't
find them.

With that restriction, you can use Assembly.GetTypes, and then go
through each type and use Type.IsAssignableFrom to find out if the type
is derived (directly or indirectly) from your base type.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
MR wrote:
I.e. need
the inherited class to know about subclasses that are inherited form
it.


You may want to look at your design here, this is generally not
considered a goal in inheritance, the point of being able to extend
objects is that the original object should not have to know anything
about it's descendant classes.

If you need to have a relationship with the descendant class and the
original class, you may be better off formally declaring what that
relationship is, and use some other mechanism (than reflection) to get
at it, perhaps a hashtable for instance or possibly a custom attribute,
personally I would favour a registration process into a hash table (or
some other list) A patterns book could help you with the design.

Cheers Tim.
Nov 16 '05 #3

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

Similar topics

17
by: Sean Ross | last post by:
Hi. Recently I made a small script to do some file transferring (among other things). I wanted to monitor the progress of the file transfer, so I needed to know the size of the files I was...
4
by: Klaus Neuner | last post by:
Hello, the function given below returns all indexes of list2 where a sublist of list2 that is identical to list1 begins. As I will need this function quite often, I would like to know if more...
5
by: Thomas Philips | last post by:
I'm teaching myself programming using Python, and have a question about subclasses. My game has two classes, Player and Alien, with identical functions, and I want to make Player a base class and...
0
by: Vera | last post by:
Hi, I have a very annoying problem, with which I NEED HELP DESPERATELY!! It smells like a bug to me, but I'm not sure. SITUATION This description is a very much simplified version of the real...
8
by: Marco | last post by:
Hi all, I have a base class and some subclasses; I need to define an array of objects from these various subclasses. What I have is something like: { //I have a base class, something like:...
0
by: MR | last post by:
I'm hoping that someone here will be able to direct me to some litrature on how to get a list of a classes subclasses. I.e. need the inherited class to know about subclasses that are inherited...
9
by: Ulrich Hobelmann | last post by:
Hi, slowly transitioning from C to C++, I decided to remodel a struct/union (i.e. type identifier as first field, union of variant types) as a class + subclasses. Switching functions are replaced...
5
by: ryanoasis | last post by:
Working on a C++ assignment and I cant figure out the problems I am having w/ Templates and Subclasses. I know there are issues with templates and certain compilers so I am not sure what the...
10
by: Karlo Lozovina | last post by:
Hi, what's the best way to keep track of user-made subclasses, and instances of those subclasses? I just need a pointer in a right direction... thanks. -- Karlo Lozovina -- Mosor
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.