code_junkie

Linq with custom base collection

Nov 13th, 2011
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. abstract class BaseCollection<T> : List<T> { ... }
  2.  
  3. class PruductCollection : BaseCollection<Product> { ... }
  4.  
  5. var products = from p in HugeProductCollection
  6. where p.Vendor = currentVendor
  7. select p;
  8. PruductCollection objVendorProducts = new PruductCollection();
  9. objVendorProducts.AddRange(products);
  10.  
  11. public static class MyExtensions
  12. {
  13. public static ProductCollection
  14. ToProducts( this IEnumerable<Product> collection )
  15. {
  16. return new ProductCollection( collection );
  17. }
  18. }
  19.  
  20.  
  21. public class ProductCollection : BaseCollection<Product>
  22. {
  23. ...
  24.  
  25. public ProductCollection( IEnumerable<Product> collection )
  26. : base( collection )
  27. {
  28. }
  29.  
  30. ...
  31. }
  32.  
  33.  
  34. var products = (from p in HugeProductCollection
  35. where p.Vendor = currentVendor
  36. select p).ToProducts();
  37.  
  38. abstract class BaseCollection<T> : List<T>
  39. {
  40. public BaseCollection(IEnumerable<T> collection)
  41. : base(collection)
  42. {
  43. }
  44. }
  45.  
  46. class PruductCollection : BaseCollection<Product>
  47. {
  48. public PruductCollection(IEnumerable<Product> collection)
  49. : base(collection)
  50. {
  51. }
  52. }
  53.  
  54. var products = from p in HugeProductCollection
  55. where p.Vendor = currentVendor
  56. select p;
  57. PruductCollection objVendorProducts = new PruductCollection(products);
Add Comment
Please, Sign In to add comment