using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace IOTContainer.SQLite { /// /// 字段信息列表 /// public class SQLiteColumnList : IList { #region 构造函数 public SQLiteColumnList() { this._columns = new List(); } #endregion #region 字段属性 /// /// 字段信息集合 /// private List _columns; /// /// 获取设置字段信息 /// /// 索引 /// 字段信息 public SQLiteColumn this[int index] { get { return this._columns[index]; } set { if (this._columns[index].ColumnName != value.ColumnName) { CheckColumnName(value.ColumnName); } this._columns[index] = value; } } /// /// 字段信息数量 /// public int Count { get { return this._columns.Count; } } public bool IsReadOnly { get { return false; } } #endregion #region 外部函数 /// /// 获取字段信息下标 /// /// 字段信息 /// 下标 public int IndexOf(SQLiteColumn item) { return this._columns.IndexOf(item); } /// /// 插入字段信息 /// /// 下标 /// 字段信息 public void Insert(int index, SQLiteColumn item) { CheckColumnName(item.ColumnName); this._columns.Insert(index, item); } /// /// 移除字段信息 /// /// 下标 public void RemoveAt(int index) { this._columns.RemoveAt(index); } /// /// 添加字段信息 /// /// 字段信息 public void Add(SQLiteColumn item) { CheckColumnName(item.ColumnName); this._columns.Add(item); } /// /// 是否包含字段信息 /// /// 字段信息 /// true:是,false:否 public bool Contains(SQLiteColumn item) { return this._columns.Contains(item); } /// /// 复制字段信息 /// /// 字段信息数组 /// 其实位置 public void CopyTo(SQLiteColumn[] array, int arrayIndex) { this._columns.CopyTo(array, arrayIndex); } /// /// 移除字段信息 /// /// 字段信息 /// true:是,false:否 public bool Remove(SQLiteColumn item) { return this._columns.Remove(item); } /// /// 获取迭代器 /// /// 迭代器 public IEnumerator GetEnumerator() { return this._columns.GetEnumerator(); } /// /// 获取迭代器 /// /// 迭代器 IEnumerator IEnumerable.GetEnumerator() { return this._columns.GetEnumerator(); } /// /// 清理 /// public void Clear() { this._columns.Clear(); } #endregion #region 内部函数 /// /// 检查列名 /// /// 列名 private void CheckColumnName(string colName) { if (this._columns.FirstOrDefault(x => x.ColumnName == colName) != null) throw new Exception("Column name of \"" + colName + "\" is already existed."); } #endregion } }