私は C#/.NET 3.5 アプリを開発しています (そのバージョンの .NET を使い続けたいと考えています)、Reflection を使用してこの問題を解決する方法がわかりません。回避策を見つけましたが、「きちんとした」ものではありません。以下のコードでは、すべての Interface 実装を検出する必要があるため、将来さらに Interface 実装を追加するときに、既存のコードを変更する必要がなくなります。
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.
}
}