나는 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 –