Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RowDataCollection : IList<RowData> {
- private List<RowData> rowList;
- internal RowDataCollection(List<RowData> data) {
- rowList = data;
- }
- // ...
- }
- public RowDataCollection Rows;
- public RowDataCollection Select(string colName, object value) {
- List<RowData> rowList = from item in Rows
- where item[colName].Value == value
- select item;
- return new RowDataCollection(rowList);
- }
- public RowDataCollection SelectRow(string colName, object value) {
- if (!String.IsNullOrEmpty(colName) && (value != null) && (0 < Rows.Count)) {
- switch (Rows[0][colName].GetValueType()) {
- case TableDataType.Boolean:
- return new RowDataCollection(Rows.Where(r => (bool)r[colName].Value == (bool)value).ToList());
- case TableDataType.Character:
- return new RowDataCollection(Rows.Where(r => (char)r[colName].Value == (char)value).ToList());
- case TableDataType.DateTime:
- return new RowDataCollection(Rows.Where(r => (DateTime)r[colName].Value == (DateTime)value).ToList());
- case TableDataType.Decimal:
- return new RowDataCollection(Rows.Where(r => (Decimal)r[colName].Value == (Decimal)value).ToList());
- case TableDataType.Integer:
- return new RowDataCollection(Rows.Where(r => (int)r[colName].Value == (int)value).ToList());
- case TableDataType.String:
- return new RowDataCollection(Rows.Where(r => r[colName].Value.ToString() == value.ToString()).ToList());
- }
- }
- return null;
- }
- public RowDataCollection SelectRow(string colName, object value) {
- List<RowData> rowList = Rows.Where(r => r[colName].Value.Equals(value)).ToList();
- return new RowDataCollection(rowList);
- }
- List<RowData> rowList = (from item in Rows
- where item[colName].Value == value
- select item).ToList();
- List<RowData> rowList = Rows.Where(item => item[colName].Value.Equals(value))
- .ToList();
- if (string.IsNullOrEmpty(colName))
- {
- throw new ArgumentException("colName");
- }
- List<RowData> rowList = (from item in Rows
- where item[colName].Value == value
- select item).ToList();
- List<RowData> rowList = (from item in Rows
- where item[colName].Value == value
- select item).ToList();
- if (colName == null)
- {
- throw new ArgumentNullException("colName");
- }
- else if (!Rows.All(row => row.HasColumn(colName)))
- {
- throw new ArgumentException("No such column " + colName, "colName");
- }
- ...
- // note the change to Any()
- else if (!Rows.Any(row => row.HasColumn(colName))
- {
- throw new ArgumentException("No such column " + colName, "colName");
- }
- List<RowData> rowList = (from item in Rows
- where item.HasColumn(colName)
- && item[colName].Value == value
- select item).ToList();
- public RowDataCollection Select(string colName, object value) {
- List<RowData> rowList = from item in Rows
- where item[colName].Value == value
- select item;
- return new RowDataCollection(rowList.ToList());
- }
Add Comment
Please, Sign In to add comment