views:

69

answers:

2

My question is very similar in concept to this question. However, I was wondering how I would programmatically identify every class in a given namespace that implements a specific interface in a method (so I can add an object of each to a List), similar to how the Stripes Framework (in Java) finds all the classes that implement the ActionBean interface.

Code samples would be great but if anything else I need need to be pointed in the right direction.

+1  A: 

Pointing you the direction >>>

Go Here

or

Alternate Route here !

Shankar Ramachandran
Thanks. For some reason I couldn't find that when searching.
Dan
@Dan pls see edit
Shankar Ramachandran
+1  A: 

You can use reflection, in particular, Type.IsAssignableFrom, to check all of the types in an assembly.

This is different than finding all of the types in a namespace, though. The hard part is that a namespace can be used across multiple assemblies, since in .NET, there is nothing special about a namespace. It's just a prefix on the actual type name, but in IL, it isn't a "System" namespace containing "Int32", it's a single System.Int32 type.

My recommendation would be to search all of teh types in an Assembly, look at whether the type name begins with your namespace name, and then check whether your interface's type is assignable from the type. If so, it implements the interface. Repeat for all assemblies defining types within the namespace in question.

Reed Copsey