We are dynamically building some SQL statements and we are utilizing the IN operator. If our value is a collection of values such that:
List<Guid> guids = 开发者_高级运维new List<Guid>()
I want to be able to provider 'guids' to my clause builder, have it verify the type and if it is enumerable create a clause like:
IN ( {Guid1}, {Guid2}, {Guid3} )
Checking that the value is IEnumerable like this:
if (value is IEnumerable)
falls down when a string is passed in (which happens pretty regularly :) ). What is the best way to validate this type of condition?
How about:
if(value .GetType().IsGenericType && value is IEnumerable)
You could try value.GetType().IsGenericType
in combination with your check for IEnumerable.
What about :
value is IEnumerable<Guid>
It's better if you expect Guid instances, isn't it ?
精彩评论