using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace Bowin.Common.Utility
{
///
/// DataRowCollection 的扩展
///
public static class DataRowCollectionExtension
{
///
/// 移除所有空行。
///
///
public static void RemoveAllEmpty(this DataRowCollection dataRowCollection)
{
if (dataRowCollection == null)
{
throw new ArgumentNullException("dataRowCollection");
}
List emptyRows = new List();
foreach (DataRow dr in dataRowCollection)
{
var temp = 0;
for (int i = 0; i < dr.Table.Columns.Count; i++)
{
if (dr[i] == null || string.IsNullOrWhiteSpace(dr[i].ToString()))
{
temp += 1;
}
}
if (temp == dr.Table.Columns.Count)
{
emptyRows.Add(dr);
}
}
dataRowCollection.RemoveRange(emptyRows);
}
///
/// 将指定的 System.Data.DataRow集合 添加到 System.Data.DataRowCollection 对象中。
///
///
///
public static void AddRange(this DataRowCollection dataRowCollection, IEnumerable collection)
{
if (dataRowCollection == null)
{
throw new ArgumentNullException("dataRowCollection");
}
if (collection == null)
{
throw new ArgumentNullException("collection");
}
foreach (DataRow dr in collection)
{
dataRowCollection.Add(dr);
}
}
///
/// 从集合中移除指定的 System.Data.DataRow 集合。
///
///
///
public static void RemoveRange(this DataRowCollection dataRowCollection, IEnumerable collection)
{
if (dataRowCollection == null)
{
throw new ArgumentNullException("dataRowCollection");
}
if (collection == null)
{
throw new ArgumentNullException("collection");
}
foreach (DataRow dr in collection)
{
dataRowCollection.Remove(dr);
}
}
}
}