I am developing C#/.NET 3.5 app (and would like to stay on that version of .NET), and can’t figure how to solve this problem using Reflection. I found workaround, but is not “neat”. Code as below, I need to discover all Interface implementations, so that in the future when adding more Interface implementations I do not need to change existing code.
interface Ii { }
class A : Ii { }
class A1 : A { }
class A2 : A { }
class A3 : A { }
class B : Ii { }
class C : Ii{ }
// maybe in future class D : Ii { }
// maybe in future class E : Ii { }
class Helper
{
static List<Type> GetAllInterfaceImplemenations()
{// do reflection magic and return ["A1","A2","A3","B","C"] ...
// I will use this method to fill comboBox-es , create objects factory, etc...
// there should be no changes if/when in future I add class D etc.
}
}