code_junkie

List<BusinessObject> or BusinessObjectCollection?

Nov 10th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. public class CollectionBase : IEnumerable
  2.  
  3. public class BusinessObjectCollection : CollectionBase
  4.  
  5. public class BusinessObjectCollection : List<BusinessObject>
  6.  
  7. var d = new Dictionary<string, int>
  8. {
  9. {"hello", 0},
  10. {"the answer to life the universe and everything is:", 42}
  11. };
  12.  
  13. class c1 : IEnumerable
  14. {
  15. void Add(int x1, int x2, int x3)
  16. {
  17. //...
  18. }
  19.  
  20. //...
  21. }
  22.  
  23. var x = new c1
  24. {
  25. {1,2,3},
  26. {4,5,6}
  27. }
  28.  
  29. var x = new List<Customer>
  30. {
  31. new Customer("Scott Wisniewski", "555-555-5555", "Seattle", "WA"),
  32. new Customer("John Doe", "555-555-1234", "Los Angeles", "CA"),
  33. new Customer("Michael Scott", "555-555-8769", "Scranton PA"),
  34. new Customer("Ali G", "", "Staines", "UK")
  35. }
  36.  
  37. class CustomerList : List<Customer>
  38. {
  39. public void Add(string name, string phoneNumber, string city, string stateOrCountry)
  40. {
  41. Add(new Customer(name, phoneNumber, city, stateOrCounter));
  42. }
  43. }
  44.  
  45. var customers = new CustomerList
  46. {
  47. {"Scott Wisniewski", "555-555-5555", "Seattle", "WA"},
  48. {"John Doe", "555-555-1234", "Los Angeles", "CA"},
  49. {"Michael Scott", "555-555-8769", "Scranton PA"},
  50. {"Ali G", "", "Staines", "UK"}
  51. }
  52.  
  53. public static int SomeCount(this IEnumerable<BusinessObject> someList)
  54.  
  55. public class BusinessObjectCollection : List<BusinessObject> {}
  56.  
  57. public IEnumerable<BusinessObject> GetBusinessObjects();
  58.  
  59. public OrderItemCollection : IEnumerable<OrderItem>
  60. {
  61. private readonly List<OrderItem> _orderItems = new List<OrderItem>();
  62.  
  63. void Add(OrderItem item)
  64. {
  65. _orderItems.Add(item)
  66. }
  67.  
  68. //implement only the list members, which are required from your domain.
  69. //ie. sum items, calculate weight etc...
  70.  
  71. private IEnumerator<string> Enumerator() {
  72. return _orderItems.GetEnumerator();
  73. }
  74.  
  75. public IEnumerator<string> GetEnumerator() {
  76. return Enumerator();
  77. }
  78. }
  79.  
  80. public MyTypeCollection : List<MyType>
  81.  
  82. using BusinessObjectCollection = List<BusinessObject>;
  83.  
  84. System.Collections.ObjectModel.Collection<BusinessObject>
Add Comment
Please, Sign In to add comment