I need to validate an object to see whether it is null, a value type, or IEnumerable<T> where T is a value type. So far I have:
if ((obj == null) || (obj .GetType().IsValueType)) { valid = true; } else if (obj.GetType().IsSubclassOf(typeof(IEnumerable<>))) { // TODO: check whether the generic parameter is a value type. }
So I’ve found that the object is null, a value type, or IEnumerable<T> for some T; how do I check whether that T is a value type?
(edit – added value type bits)
You need to check all the interfaces it implements (note it could in theory implement
IEnumerable<T>for multipleT):