最近项目要对采集的数据图谱进行翻页,然而数据源类型不一致,不过其本质都是集合.
1 public class MyPage<T> 2 { 3 /// <summary> 4 /// 当前显示页 5 /// </summary> 6 private int _currentIndex; 7 8 public int CurrentIndex 9 { 10 get 11 { 12 return _currentIndex; 13 } 14 } 15 16 /// <summary> 17 /// 比较数据源 18 /// </summary> 19 private ICollection<T> _dataSource; 20 21 /// <summary> 22 /// 数据总条数 23 /// </summary> 24 private int _total; 25 26 public bool IsBigOne 27 { 28 get 29 { 30 return _dataSource.Count > 1; 31 } 32 } 33 34 /// <summary> 35 /// 初始化 36 /// </summary> 37 /// <param name="data"></param> 38 public ComParisonPage(ICollection<T> data) 39 { 40 if (data != null) 41 { 42 _dataSource = data; 43 _currentIndex = 0; 44 45 } 46 } 47 48 /// <summary> 49 /// 上一页 50 /// </summary> 51 public void Prev() 52 { 53 _currentIndex -= 1; 54 if (_currentIndex < 0) _currentIndex = 0; 55 } 56 57 /// <summary> 58 /// 下一页 59 /// </summary> 60 public void Next() 61 { 62 _currentIndex += 1; 63 if (_currentIndex >= _dataSource.Count - 1) _currentIndex = _dataSource.Count - 1; 64 } 65 66 public T Current 67 { 68 get 69 { 70 return _dataSource.ElementAt(_currentIndex); 71 } 72 } 73 74 75 public bool IsTop 76 { 77 get 78 { 79 return _currentIndex == 0; 80 } 81 } 82 83 public bool IsBottom 84 { 85 get 86 { 87 return _currentIndex >= _dataSource.Count - 1; 88 } 89 } 90 }
下面就可以实例这个类了:
private Page<KeyValuePair<double, Spectrum>> P1 = null;
private Page<model> p2 = null;
时间: 2024-10-03 19:52:36