
using#region using
using System;
using System.Collections;
#endregion

namespace ProgrammerLife.Utility


{

/**//// <summary>
/// 强类型列表基类
/// </summary>
public abstract class IStrongTypeBaseList:IList

{

private fields#region private fields

/**//// <summary>
/// 内部集合字段
/// </summary>
protected ArrayList _innerList =null;

/**//// <summary>
/// 元素类型字段
/// </summary>
private Type _elementType =null;
#endregion


constructor#region constructor

/**//// <summary>
/// 构造函数
/// </summary>
/// <param name="pElementType">元素类型</param>
public IStrongTypeBaseList(Type pElementType)

{
this.init();
this._elementType =pElementType;
}
#endregion


private functions#region private functions

/**//// <summary>
/// 初始化
/// </summary>
private void init()

{
this._innerList=new ArrayList();
}
#endregion


Eimi( explicit interface members implementation)#region Eimi( explicit interface members implementation)

properties#region properties

/**//// <summary>
/// 获取一个值,指示IEntityList是否只读
/// </summary>
bool System.Collections.IList.IsReadOnly

{

get
{return this._innerList.IsReadOnly;}
}

/**//// <summary>
/// 索引指示器
/// </summary>
object System.Collections.IList.this[int pIndex]

{

get
{return this._innerList[pIndex];}
set

{
if(value == null)
throw new NullElementException("集合不能设置一个为null的元素!");
if(value.GetType() != this._elementType)
throw new UnconsistentElementTypeException(string.Format("集合期望的元素类型为{0},而设置的索引项的类型为{1}!",this._elementType.ToString(),value.GetType().ToString()));
this._innerList[pIndex]=value;
}
}

/**//// <summary>
/// 获取一个值,指示集合是否有固定大小
/// </summary>
bool System.Collections.IList.IsFixedSize

{

get
{return this._innerList.IsFixedSize;}
}

/**//// <summary>
/// 获取一个值,指示集合是否同步
/// </summary>
bool System.Collections.ICollection.IsSynchronized

{

get
{return this._innerList.IsSynchronized;}
}

/**//// <summary>
/// 获取可用于同步对集合访问的对象
/// </summary>
object System.Collections.ICollection.SyncRoot

{

get
{return this._innerList.SyncRoot;}
}
#endregion


methods#region methods

/**//// <summary>
/// 在指定的位置插入一个元素
/// </summary>
/// <param name="pIndex"></param>
/// <param name="pInstance"></param>
void System.Collections.IList.Insert(int pIndex, object pInstance)

{
if(pInstance == null)
throw new NullElementException("集合不能插入一个为null的元素!");
if(pInstance.GetType() != this._elementType)
throw new UnconsistentElementTypeException(string.Format("集合期望的元素类型为{0},而插入的元素的类型为{1}!",this._elementType.ToString(),pInstance.GetType().ToString()));
this._innerList.Insert(pIndex,pInstance);
}

/**//// <summary>
/// 移除特定对象的第一个匹配
/// </summary>
/// <param name="pInstance"></param>
void System.Collections.IList.Remove(object pInstance)

{
this._innerList.Remove(pInstance);
}

/**//// <summary>
/// 确定某个实例是否存在于集合中
/// </summary>
/// <param name="pInstance"></param>
/// <returns></returns>
bool System.Collections.IList.Contains(object pInstance)

{
if(pInstance == null)
return false;
if(pInstance.GetType() != this._elementType)
return false;
return this._innerList.Contains(pInstance);
}

/**//// <summary>
/// 搜索指定的对象,并返回第一个匹配对象的索引
/// </summary>
/// <param name="pInstance"></param>
/// <returns></returns>
int System.Collections.IList.IndexOf(object pInstance)

{
if(pInstance == null)
return EmptyHandle.NotFoundIndex;
if(pInstance.GetType() != this._elementType)
return EmptyHandle.NotFoundIndex;
return this._innerList.IndexOf(pInstance);
}

/**//// <summary>
/// 将元素添加到集合的结尾处,并返回它的索引。
/// </summary>
/// <param name="pInstance"></param>
/// <returns></returns>
int System.Collections.IList.Add(object pInstance)

{
if(pInstance == null)
throw new NullElementException("集合不能插入一个为null的元素!");
if(pInstance.GetType() != this._elementType)
throw new UnconsistentElementTypeException(string.Format("集合期望的元素类型为{0},而新增的元素的类型为{1}!",this._elementType.ToString(),pInstance.GetType().ToString()));
return this._innerList.Add(pInstance);;
}
#endregion

#endregion


public methods#region public methods

/**//// <summary>
/// 移除实体集合类中指定索引处的元素
/// </summary>
/// <param name="pIndex">指定的索引</param>
public void RemoveAt(int pIndex)

{
this._innerList.RemoveAt(pIndex);
}

/**//// <summary>
/// 移除所有的元素
/// </summary>
public void Clear()

{
this._innerList.Clear();
}

/**//// <summary>
/// 拷贝集合中从指定索引开始的元素到一个数组中
/// </summary>
/// <param name="pArray"></param>
/// <param name="pIndex"></param>
public void CopyTo(Array pArray, int pIndex)

{
this._innerList.CopyTo(pArray,pIndex);
}

/**//// <summary>
/// 获取集合的枚举数
/// </summary>
/// <returns></returns>
public IEnumerator GetEnumerator()

{
return this._innerList.GetEnumerator();
}
#endregion


properties#region properties

/**//// <summary>
/// 获取集合中实际包含的元素的个数
/// </summary>
public int Count

{

get
{return this._innerList.Count;}
}

/**//// <summary>
/// 元素的类型
/// </summary>
public Type ElementType

{

get
{return this._elementType;}
}
#endregion
}
}

posted on
2007-02-03 16:31
东风31
阅读(
174)
评论()
收藏
举报