internal void Create <TSource>(数据结构.IEnumerable <TSource> source, 内置委托.Func <TSource, TKey> keyselector, 内置委托.Func <TSource, TElement> elementselector) { //对数据集合每个元素进行遍历 IEnumerator <TSource> tor = source.GetEnumerator(); while (tor.MoveNext()) { GetGrouping(keyselector(tor.Current), true).Add(elementselector(tor.Current)); } }
/// <summary> /// 将枚举类型的数据源直接转换为MyList /// </summary> /// <param name="source"></param> public MyList(数据结构.IEnumerable <T> source) { if (source != null) { 数据结构.IEnumerator <T> tor = source.GetEnumerator(); while (tor.MoveNext()) { this.Add(tor.Current); } } }
public void SourceToArray(数据结构.IEnumerable <TNeedChange> changesource) { //微软源代码数据转化的方法:1.如果数据源实现了ICollection 的接口则可以把数据进行 //根据数组的方法的形式进行转化 2.另一个方法是通用的一种转化的方法 //====自定义的数据没有自定义的ICollection的接口 MyList <TNeedChange> templist = new MyList <TNeedChange>(); templist = changesource.ToList(); if (templist.Count > 0) { this._temp = new TNeedChange[templist.Count]; for (int i = 0; i < templist.Count; i++) { _temp[i] = templist[i]; } } }
/// <summary> /// 构造函数 /// </summary> /// <param name="source"></param> /// <param name="keyselector"></param> public OrderThenBySequence(数据结构.IEnumerable <TSource> source, 内置委托.Func <TSource, TKey> keyselector, 系统内置接口.IComparer <TKey> comparer) { if (source == null) { throw new Exception("需要排序的数据源不能为空"); } if (keyselector == null) { throw new Exception("需要排序的字段不能为空"); } this.comparer = comparer; this.source = source; this.keyselector = keyselector; this.parent = null;//如果是orderby那么就说明只需要创建一个序列,也就没有了父级序列 //如果用户没有定义默认的比较器就使用系统默认的比较器 if (this.comparer == null) { 数据结构.Comparer <TKey> comparerclass = new Comparer <TKey>(); this.comparer = comparerclass.Default; } }