Question

How do I check if class inherits from my class DataSource (abstract class).

here is what I got:

var q = from t in Assembly.Load(new AssemblyName("DefaultDataSources")).GetTypes()
                where t.IsClass
                select t;

I don't know what condition to add :(

Was it helpful?

Solution

It sounds like you just want:

var query = Assembly.Load(...)
                    .GetTypes()
                    .Where(t => typeof(DataSource).IsAssignableFrom(t));

(The IsAssignableFrom part is the interesting bit, but I gave the full query as this is a good example of a case where a query expression just gets in the way - a single call to the Where extension method is simpler.)

OTHER TIPS

IsAssignableFrom().

This link shows the reverse process - discovering all the derivations of a base class.

Discovering derived types using reflection

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top