I have an interface, and some classes that inherit from it.
public interface IFoo {}
public class Bar : IFoo {}
public class Baz : IFoo {}
If I get the types which implement IFoo
, how can I decide if the type will represent a Bar
or a Baz
(without actually creating the object)?
// Get all types in assembly.
Type[] theTypes = asm.GetTypes();
// See if a type implement IFoo.
for (int i = 0; i < theTypes.Length; i++)
{
Type t = theTypes[i].GetInterface("IFoo");
if (t != null)
{
// TODO: is t a Bar or a Baz?
}
}