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

How to find derived classes?

Hello all,

Is there a way to find all classes that are derived from a specific
base type?
Within the namespace of my project i define a base type that may be
inherited for future expansion, so when checking for this class i need
to know all specific implemented types.

Right now I have a code snippet like:
Type[] types = new Type[] { typeof(FileData),
typeof(FileData_Image) };
foreach (Type t in types) {
(...)

What I would ideally like to have is something like:
Type[] types =
typeof(myBaseType).GetAllClassesThatDeriveFromThis Class("withinMyNamespace");
foreach (Type t in types) {
(...)

Is this possible?

Chris

Mar 4 '07 #1
1 1656
Zark3 <Za******@gmail.comwrote:
Is there a way to find all classes that are derived from a specific
base type?
Yes, but not in a one-liner. Basically, for each assembly you're
interested in, you need to look through all the types, and then check
each type with IsSubclassOf.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 4 '07 #2

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

Similar topics

4
by: Brad Kartchner | last post by:
I'm attempting to write a program with several child classes derived from a single parent class. The parent class has a couple of variables that need to be present in each of the child classes. ...
5
by: Nathan Bullock | last post by:
Hi, I have a base class, say Base and there are two classes, say Class1 and Class2 which are derived from Base. Is there any way for me, say from a static method in Base, to get a list of all...
10
by: William Stacey | last post by:
I know the following is not allowed, but shouldn't it be? sharedObject is part of Derived and should be able to be set in the constructor - no? tia public abstract class Base1 { protected...
5
by: Hans De Schrijver | last post by:
Where can I find a list of pre-defined exceptions for .NET? Whenever possible, I'd rather use existing exception constants rather than defining my own, unless no suitable one has been predefined. ...
13
by: z. f. | last post by:
Hi, i have a class that is derived from System.Web.UI.Page, and this is the class i use in my application as PageBase. all other page classes are deriverd from my PageBase instead of the...
8
by: Manuel | last post by:
Hi! If I've a vector filled with abstract classes, can I push in it the derived classes too? Even if derived classes have new methods? I've done some experiments, and it seem I can push the...
6
by: ivan.leben | last post by:
I want to write a Mesh class using half-edges. This class uses three other classes: Vertex, HalfEdge and Face. These classes should be linked properly in the process of building up the mesh by...
9
by: desktop | last post by:
On this page: http://www.eptacom.net/pubblicazioni/pub_eng/mdisp.html Shape specify the virtual function: virtual double Intersect( const Shape& s) = 0; then the derived class Circle...
15
by: Bob Johnson | last post by:
I have a base class that must have a member variable populated by, and only by, derived classes. It appears that if I declare the variable as "internal protected" then the base class *can*...
4
by: Josh Valino | last post by:
Hi group, Is there a way in C# (.Net 3.5 FW) for me to define an abstract class that has some properties, and then in each derived class, select which properties I'd like available and which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.