这很好:
var expectedType = typeof(string);
object value = "...";
if (value.GetType().IsAssignableFrom(expectedType))
{
...
}
但如何在不将expectedType
设置为typeof(string[])
的情况下判断值是否为字符串数组?我想做一些事情,比如:
var expectedType = typeof(string);
object value = new[] {"...", "---"};
if (value.GetType().IsArrayOf(expectedType)) // <---
{
...
}
这可能吗?