「Type tとして変数/引数に用意された型に対するIEnumerable<T>の型オブジェクトを取得するにはどうすれば良いのか」
「IEnumerable<T>のTに入って欲しいわけだね」
「そうだ」
「それでどうするの?」
「以下のように2段構えで処理すれば良いようだ」
using System;
using System.Collections.Generic;
class Program
{
private static void test(Type t)
{
var a = typeof(IEnumerable<>);
var b = a.MakeGenericType(t);
Console.WriteLine(b.Name);
Console.WriteLine(b.GenericTypeArguments[0]);
}
static void Main(string[] args)
{
test(typeof(int));
}
}
実行結果 §
IEnumerable`1
System.Int32
感想 §
「いやー、最初うっかり勘違いして他のAPI調べてたよ。わははは」
「笑うなっ!」
「あれほどリフレクション使いまくってた割に、たまたま使ってなかった盲点も多いな」