The Setup
I've got a method called WhereIn() that accepts a params object[] values:
public bool WhereIn(params object[] values)
The Problem
Unfortunately is it's really easy to make the mistake of calling WhereIn(values.Select(v => v.Id))
.
This results a Linq expression being passed in, rather that the values getting enumerated to an array. How do I overload my method to accept the linq expression?
My Best Guess
My current best guess is to make an IEnumerable overload, and then have to check for it being a string, and then stuffing the string into an object array to call the other overload:
public bool WhereIn<T>(IEnumerable<T> values){
if(values.GetType().Name == "String"){
return WhereIn(new object[]{values});
} else {
// Do Stuff
}
}
I'm not really happy about having to manually check for a string type, and I'm afraid I might miss some other class that implements IEnumerable, that should be wrapped in an object array .