Reputation: 29
Is something like that possible:
int testvar = 0;
var query = PrimaryDataSource.AsEnumerable().Where(r =>
r.Field<testvar.GetType()>("col") == testvar);
But I don't want this:
int testvar = 0;
if (testvar is int)
{
var query = PrimaryDataSource.AsEnumerable().Where(r =>
r.Field<int>("col") == testvar);
}
Upvotes: 0
Views: 77
Reputation: 203812
Just don't use Field
to get the value; get it as an object:
var query = PrimaryDataSource.AsEnumerable().Where(r =>
object.Equals(r["col"], testvar));
The whole point of using generics is to have static typing when you know the type involved statically. Since you don't, there's no benefit to using it.
Upvotes: 3