私はTypeオブジェクトの特定のインスタンスは一般的な「IEnumerableを」であるかどうかを検出しようとしている....NETリフレクション:検出IEnumerableを<T>
私が思い付くことができる最高は次のとおりです。
// theType might be typeof(IEnumerable<string>) for example... or it might not
bool isGenericEnumerable = theType.GetGenericTypeDefinition() == typeof(IEnumerable<object>).GetGenericTypeDefinition()
if(isGenericEnumerable)
{
Type enumType = theType.GetGenericArguments()[0];
etc. ...// enumType is now typeof(string)
しかし、これは少し間接的です - これを行うためのより直接的/エレガントな方法がありますか?
私のフォローアップをご覧ください:http://stackoverflow.com/questions/1650310/net-reflection-determining-whether-an-array-of-t-would-be-convertible-to-some-o –