Wednesday, 2 October 2013

Check if IEnumerable is of a ValueType (at runtime)

Check if IEnumerable is of a ValueType (at runtime)

How do I check if an object I receive as a method result is not ValueType
and not IEnumerable<ValueType>?
Here is what I wrote:
MethodInfo selectedOverload = SelectOverload(selectedMethodOverloads);
object result = ExecuteAndShowResult(selectedOverload);
ExploreResult(result);
private static void ExploreResult(object result)
{
if (result != null &&
!(result is ValueType) &&
!((IEnumerable)result).GetType().GetProperty("Item").PropertyType) is
ValueType)
)
Console.WriteLine("explore");
}
Unfortunately type of PropertyType is Type, its content is the type I need
to check (e.g. int) but I don't know how to.

No comments:

Post a Comment