So I ran into a scenario where I thought a generic would be a good
solution but I couldn't find a simple way to handle the conventions.
Can anyone think of a solution to let me get some reusability out of
the below sudo code?

IQueryable<x> query = an IQueryable where the element type x has a
property "Key" that stores a string representation of some value type;
T lookup = some value;

//T as int
var bands = from i in query
                  let b = Convert.ToInt32(i.Key); // b is T
                  where b > (T) lookup
                  select b;

return query.Single(i => Convert.ToInt32(i.Key) == bands.Min());


//T as decimal
var bands = from i in query
                  let b = Convert.ToDecimal(i.Key)
                  where b > (T) lookup
                  select b;

return query.Single(i => Convert.ToDecimal(i.Key) == bands.Min());


//T as DateTime
var bands = from i in query
                  let b = Convert.ToDateTime(i.Key)
                  where b > (T) lookup
                  select b;

return query.Single(i => Convert.ToDateTime(i.Key) == bands.Min());

It's not holding up my project or anything but I would like to cut out
a lot of the redundant code I've ended up with.
Thanks in advance.

Reply via email to