SomeGenericMethod<SomeGenericType<>>
に電話できないのはなぜですか?ジェネリックメソッドをジェネリックメソッドに渡すにはどうすればよいですか?
class NotGeneric { }
class Generic<T> { }
class Program
{
static void Main(string[] args)
{
PrintType(typeof(NotGeneric));
PrintType(typeof(Generic<>));
PrintType<NotGeneric>();
PrintType<Generic<>>(); // compiler goes crazy here
}
static void PrintType<T>()
{
Console.WriteLine(typeof(T));
}
static void PrintType(Type t)
{
Console.WriteLine(t);
}
}
基本的に 'typeof'はジェネリック型が定義されていないジェネリッククラス名をとることができますが、ジェネリック型として型を渡すと' Generic <> 'は完全に定義された型でなければなりません。 – juharr
@juharrここにあるように、今のところ、最高の答えはコメントです。そうすることは不可能**と言うのは安全ですか? – talles
私はrbaghbanliが同じことを言っていると思います。しかし、ジェネリック型として 'Generic <> 'を渡すことはできません。 'typeof(Generic