예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public KeyValueItemCollection ToKeyValueItemCollection()
        {
            KeyValueItemCollection result = new KeyValueItemCollection();

            foreach (var item in ListItems)
            {
                result.Add(item);
            }
            return(result);
        }
        /// <summary>
        /// 获取按照KeyValueItem项中的Key排序的结果集
        /// </summary>
        /// <returns></returns>
        public KeyValueItemCollection OrderByKey()
        {
            var kvis = new List <KeyValueItem>();

            foreach (KeyValueItem kvi in this.List)
            {
                kvis.Add(kvi);
            }
            var kvic = new KeyValueItemCollection();

            foreach (var kvi in kvis.OrderBy(item => item.Key))
            {
                kvic.Add(kvi);
            }
            return(kvic);
        }
        /// <summary>
        /// 排除重复主键值的记录
        /// </summary>
        /// <returns></returns>
        public KeyValueItemCollection Distinct()
        {
            var result = new KeyValueItemCollection();

            foreach (KeyValueItem kvi in List)
            {
                bool exist = false;
                foreach (KeyValueItem kviResult in result)
                {
                    if (kvi.Key == kviResult.Key)
                    {
                        exist = true;
                        break;
                    }
                }
                if (exist)
                {
                    continue;
                }
                result.Add(kvi);
            }
            return(result);
        }