Well you'll have to use reflection - you may also use delegates, but it's not entirely clear; it will depend on what you're doing.
Assembly.GetTypes()
will return all the types within an assembly; you can use Type.IsAssignableFrom()
to check whether a type implements an interface or derives from another particular type, Type.Namespace
to check the namespace etc. Activator.CreateInstance()
will create an instance of a type by calling the parameterless constructor (if there is one) or you can call a constructor with parameters using other overloads of CreateInstance
or by fetching it first with Type.GetConstructors()
.
If you've tested whether a type implements an interface then after constructing an instance you can cast the reference to that interface, and call the methods within that interface without using any more reflection. If you only know the name of the method at execution time then you'll need to call Type.GetMethod()
to get a MethodInfo
and then Invoke()
to invoke it.
All of this is somewhat error-prone and complicated of course - if you can find any way of staying within static typing, that will make your life easier. What's the bigger picture here? What are you trying to achieve?