Tôi đang cố gắng để phát hiện nếu một trường hợp đặc biệt của một đối tượng Type là một generic "IEnumerable" ...NET Reflection: Phát hiện IEnumerable <T>
Điều tốt nhất tôi có thể đưa ra là:
// 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)
Nhưng điều này có vẻ hơi gián tiếp - có cách trực tiếp/thanh lịch hơn để làm điều này không?
vui lòng xem theo dõi của tôi: http://stackoverflow.com/questions/1650310/net-reflection-determining-whether-an-array-of-t-would-be-convertible-to-some-o –