This works fine:
var expectedType = typeof(string);
object value = \"...\";
if (value.GetType().IsAssignableFrom(expectedType))
{
...
}
<
value.GetType().GetElementType() == typeof(string)
as an added bonus (but I'm not 100% sure. This is the code I use...)
var ienum = value.GetType().GetInterface("IEnumerable`1");
if (ienum != null) {
var baseTypeForIEnum = ienum.GetGenericArguments()[0]
}
with this you can look for List, IEnumerable... and get the T.