2011-12-23 91 views

回答

0
bool canCast = (fieldInfo.FieldType == typeof(SortedList) || 
       (fieldInfo.FieldType.IsSubclassOf(typeof(SortedList))); 
0
if ((fieldInfo.FieldType == typeof(SortedList)) || fieldInfo.FieldType.IsSubclassOf(typeof(SortedList)) 
    Console.WriteLine("Field {0} is of type {1}", fieldInfo.Name, typeof(blah.Name)); 

此代码是未经测试,但大致就是我以前使用过。

9

您可以使用IsAssignableFrom方法来执行此测试,像这样:

var isSortedList = typeof(SortedList).IsAssignableFrom(fieldInfo.FieldType); 
+1

这其实是一个更好的答案.. 。 – ivowiblo 2011-12-24 04:24:16

相关问题