staafl

Strinq

Jan 17th, 2014
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. static class Strinq
  2. {
  3. public IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> seq, string property)
  4. {
  5. var prop = typeof(TSource).GetProperty(property);
  6. return seq.Select(s => prop.GetValue(s)).Cast<TResult>();
  7. }
  8.  
  9. public IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> seq, string property, TSource value)
  10. {
  11. var prop = typeof(TSource).GetProperty(property);
  12. return seq.Where(s => Object.Equals(s, (TSource)prop.GetValue(s)));
  13. }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment