私はジェネリッククラスを次のようにしています:
public interface IFoo<T> where T : class
{
IList<T> GetFoo();
}
public class Foo<T> : IFoo<T> where T : class
{
public IList<T> GetFoo()
{
//return something in here
}
}
そして、次のようなアセンブリの型のコレクションからそのクラスを使用したいと思います。
public class Bar
{
public IList<string> GetTheFoo()
{
IList<Type> theClass = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.IsClass).ToList();
var theList = new List<string>();
foreach (Type theType in theClass)
{
//not working...
theList.Add(new Foo<theType>().GetFoo() );
}
}
}
しかし、コンパイラはリストから型を受け入れることができません。これを回避するにはどうすればよいですか?