C#で特定のGenericAbstractを実装したクラスを列挙
C#のジェネリック型でType判定をisで実装するとコンパイルエラーが出るので回避方法をメモ。
List<Type> types = new List<Type>(); Assembly asm = Assembly.GetExecutingAssembly(); Array.ForEach(asm.GetTypes(), type => { if (type.BaseType == null || !type.BaseType.IsGenericType) { return; } if (typeof(TestAbstract<>).IsAssignableFrom(type.BaseType.GetGenericTypeDefinition())) { types.Add(type); } }); return types.ToArray();