I have propertyValue
which is an object passed into my function.
I can assume that this is an IEnumerable
of some kind, however due to the interface contract I must accept it as an object
rather than directly as an IEnumerable
.
When I try to cast my value to an IEnumerable<object>
, so that I can get the length, I get an InvalidCastException
.
var length = ((IEnumerable<object>) propertyValue).Cast<object>().Count();
I get the following exception:
System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Collections.Generic.IEnumerable`1[System.Object]'.