Guest User

Untitled

a guest
Jul 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. public class RowDataCollection : IList<RowData> {
  2. private List<RowData> rowList;
  3.  
  4. internal RowDataCollection(List<RowData> data) {
  5. rowList = data;
  6. }
  7. // ...
  8. }
  9.  
  10. public RowDataCollection Rows;
  11.  
  12. public RowDataCollection Select(string colName, object value) {
  13. List<RowData> rowList = from item in Rows
  14. where item[colName].Value == value
  15. select item;
  16. return new RowDataCollection(rowList);
  17. }
  18.  
  19. public RowDataCollection SelectRow(string colName, object value) {
  20. if (!String.IsNullOrEmpty(colName) && (value != null) && (0 < Rows.Count)) {
  21. switch (Rows[0][colName].GetValueType()) {
  22. case TableDataType.Boolean:
  23. return new RowDataCollection(Rows.Where(r => (bool)r[colName].Value == (bool)value).ToList());
  24. case TableDataType.Character:
  25. return new RowDataCollection(Rows.Where(r => (char)r[colName].Value == (char)value).ToList());
  26. case TableDataType.DateTime:
  27. return new RowDataCollection(Rows.Where(r => (DateTime)r[colName].Value == (DateTime)value).ToList());
  28. case TableDataType.Decimal:
  29. return new RowDataCollection(Rows.Where(r => (Decimal)r[colName].Value == (Decimal)value).ToList());
  30. case TableDataType.Integer:
  31. return new RowDataCollection(Rows.Where(r => (int)r[colName].Value == (int)value).ToList());
  32. case TableDataType.String:
  33. return new RowDataCollection(Rows.Where(r => r[colName].Value.ToString() == value.ToString()).ToList());
  34. }
  35. }
  36. return null;
  37. }
  38.  
  39. public RowDataCollection SelectRow(string colName, object value) {
  40. List<RowData> rowList = Rows.Where(r => r[colName].Value.Equals(value)).ToList();
  41. return new RowDataCollection(rowList);
  42. }
  43.  
  44. List<RowData> rowList = (from item in Rows
  45. where item[colName].Value == value
  46. select item).ToList();
  47.  
  48. List<RowData> rowList = Rows.Where(item => item[colName].Value.Equals(value))
  49. .ToList();
  50.  
  51. if (string.IsNullOrEmpty(colName))
  52. {
  53. throw new ArgumentException("colName");
  54. }
  55.  
  56. List<RowData> rowList = (from item in Rows
  57. where item[colName].Value == value
  58. select item).ToList();
  59.  
  60. List<RowData> rowList = (from item in Rows
  61. where item[colName].Value == value
  62. select item).ToList();
  63.  
  64. if (colName == null)
  65. {
  66. throw new ArgumentNullException("colName");
  67. }
  68. else if (!Rows.All(row => row.HasColumn(colName)))
  69. {
  70. throw new ArgumentException("No such column " + colName, "colName");
  71. }
  72.  
  73. ...
  74. // note the change to Any()
  75. else if (!Rows.Any(row => row.HasColumn(colName))
  76. {
  77. throw new ArgumentException("No such column " + colName, "colName");
  78. }
  79.  
  80. List<RowData> rowList = (from item in Rows
  81. where item.HasColumn(colName)
  82. && item[colName].Value == value
  83. select item).ToList();
  84.  
  85. public RowDataCollection Select(string colName, object value) {
  86. List<RowData> rowList = from item in Rows
  87. where item[colName].Value == value
  88. select item;
  89. return new RowDataCollection(rowList.ToList());
  90. }
Add Comment
Please, Sign In to add comment