views:

84

answers:

4

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?

+4  A: 

How about:

if(value .GetType().IsGenericType && value is IEnumerable)
Vivek
+4  A: 

You could try value.GetType().IsGenericType in combination with your check for IEnumerable.

Nick
He beat you by a minute :)
Adam Driscoll
+2  A: 

Duplicate of this?

thekaido
+2  A: 

What about :

value is IEnumerable<Guid>

It's better if you expect Guid instances, isn't it ?

Seb