/******************************************************************************* * Copyright © 2016 HT.Cloud.Framework 版权所有 * Author: HT.Cloud * Description: WaterCloud快速开发平台 * Website: *********************************************************************************/ using System.Collections; using System.Collections.Generic; using System.Linq; namespace HT.Cloud.Code { public static partial class Extensions { /// /// 获取表里某页的数据 /// /// 表数据 /// 当前页 /// 分页大小 /// 返回总页数 /// 返回当页表数据 public static List GetPage(this List data, int pageIndex, int pageSize, out int allPage) { allPage = 1; return null; } /// /// IList转成List /// /// /// /// public static List IListToList(IList list) { T[] array = new T[list.Count]; list.CopyTo(array, 0); return new List(array); } /// /// 去除空元素 /// public static List removeNull(List oldList) { // 临时集合 List listTemp = new List(); foreach (var item in oldList) { if (!string.IsNullOrEmpty(item)) { listTemp.Add(item); } } return listTemp; } } public class ExtList : IEqualityComparer where T : class, new() { private string[] comparintFiledName = { }; public ExtList() { } public ExtList(params string[] comparintFiledName) { this.comparintFiledName = comparintFiledName; } bool IEqualityComparer.Equals(T x, T y) { if (x == null && y == null) { return false; } if (comparintFiledName.Length == 0) { return x.Equals(y); } bool result = true; var typeX = x.GetType();//获取类型 var typeY = y.GetType(); foreach (var filedName in comparintFiledName) { var xPropertyInfo = (from p in typeX.GetProperties() where p.Name.Equals(filedName) select p).FirstOrDefault(); var yPropertyInfo = (from p in typeY.GetProperties() where p.Name.Equals(filedName) select p).FirstOrDefault(); result = result && xPropertyInfo != null && yPropertyInfo != null && xPropertyInfo.GetValue(x, null).ToString().Equals(yPropertyInfo.GetValue(y, null)); } return result; } int IEqualityComparer.GetHashCode(T obj) { return obj.ToString().GetHashCode(); } } }