Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Collections.Specialized;
  6. using System.ComponentModel;
  7. using System.Globalization;
  8. using System.Linq;
  9.  
  10. namespace ChequeadorDeDespiece.Base
  11. {
  12. /// <summary>
  13. /// Interface genérica para el uso de <see cref="T:System.ComponentModel.ICollectionView" /> de modo genérico.
  14. /// </summary>
  15. /// <typeparam name="T">Cualquier objeto.</typeparam>
  16. public interface ICollectionView<T> : IEnumerable<T>, ICollectionView
  17. {
  18. IEnumerable<T> SourceCollectionGeneric { get; }
  19. }
  20.  
  21. public class MyCollectionViewGeneric<T> : ICollectionView<T>
  22. {
  23. private readonly ICollectionView mCollectionView;
  24.  
  25. public MyCollectionViewGeneric(ICollectionView generic)
  26. {
  27. mCollectionView = generic;
  28. }
  29.  
  30. private class MyEnumerator : IEnumerator<T>
  31. {
  32. private readonly IEnumerator mEnumerator;
  33. public MyEnumerator(IEnumerator enumerator)
  34. {
  35. mEnumerator = enumerator;
  36. }
  37.  
  38. public void Dispose()
  39. {
  40. }
  41.  
  42. public bool MoveNext()
  43. {
  44. return mEnumerator.MoveNext();
  45. }
  46.  
  47. public void Reset()
  48. {
  49. mEnumerator.Reset();
  50. }
  51.  
  52. public T Current => (T)mEnumerator.Current;
  53.  
  54. object IEnumerator.Current => Current;
  55. }
  56.  
  57. public IEnumerator<T> GetEnumerator()
  58. {
  59. return new MyEnumerator(mCollectionView.GetEnumerator());
  60. }
  61.  
  62. IEnumerator IEnumerable.GetEnumerator()
  63. {
  64. return mCollectionView.GetEnumerator();
  65. }
  66.  
  67. public bool Contains(object item)
  68. {
  69. return mCollectionView.Contains(item);
  70. }
  71.  
  72. public void Refresh()
  73. {
  74. mCollectionView.Refresh();
  75. }
  76.  
  77. public IDisposable DeferRefresh()
  78. {
  79. return mCollectionView.DeferRefresh();
  80. }
  81.  
  82. public bool MoveCurrentToFirst()
  83. {
  84. return mCollectionView.MoveCurrentToFirst();
  85. }
  86.  
  87. public bool MoveCurrentToLast()
  88. {
  89. return mCollectionView.MoveCurrentToLast();
  90. }
  91.  
  92. public bool MoveCurrentToNext()
  93. {
  94. return mCollectionView.MoveCurrentToNext();
  95. }
  96.  
  97. public bool MoveCurrentToPrevious()
  98. {
  99. return mCollectionView.MoveCurrentToPrevious();
  100. }
  101.  
  102. public bool MoveCurrentTo(object item)
  103. {
  104. return mCollectionView.MoveCurrentTo(item);
  105. }
  106.  
  107. public bool MoveCurrentToPosition(int position)
  108. {
  109. return mCollectionView.MoveCurrentToPosition(position);
  110. }
  111.  
  112. public CultureInfo Culture
  113. {
  114. get => mCollectionView.Culture;
  115. set => mCollectionView.Culture = value;
  116. }
  117.  
  118. public IEnumerable SourceCollection => mCollectionView.SourceCollection;
  119.  
  120. public Predicate<object> Filter
  121. {
  122. get => mCollectionView.Filter;
  123. set => mCollectionView.Filter = value;
  124. }
  125.  
  126. public bool CanFilter => mCollectionView.CanFilter;
  127.  
  128. public SortDescriptionCollection SortDescriptions => mCollectionView.SortDescriptions;
  129.  
  130. public bool CanSort => mCollectionView.CanSort;
  131.  
  132. public bool CanGroup => mCollectionView.CanGroup;
  133.  
  134. public ObservableCollection<GroupDescription> GroupDescriptions => mCollectionView.GroupDescriptions;
  135.  
  136. public ReadOnlyObservableCollection<object> Groups => mCollectionView.Groups;
  137.  
  138. public bool IsEmpty => mCollectionView.IsEmpty;
  139.  
  140. public object CurrentItem => mCollectionView.CurrentItem;
  141.  
  142. public int CurrentPosition => mCollectionView.CurrentPosition;
  143.  
  144. public bool IsCurrentAfterLast => mCollectionView.IsCurrentAfterLast;
  145.  
  146. public bool IsCurrentBeforeFirst => mCollectionView.IsCurrentBeforeFirst;
  147.  
  148. public event CurrentChangingEventHandler CurrentChanging
  149. {
  150. add
  151. {
  152. lock (mObjectLock)
  153. {
  154. mCollectionView.CurrentChanging += value;
  155. }
  156. }
  157. remove
  158. {
  159. lock (mObjectLock)
  160. {
  161. mCollectionView.CurrentChanging -= value;
  162. }
  163. }
  164. }
  165.  
  166. private readonly object mObjectLock = new object();
  167. public event EventHandler CurrentChanged
  168. {
  169. add
  170. {
  171. lock (mObjectLock)
  172. {
  173. mCollectionView.CurrentChanged += value;
  174. }
  175. }
  176. remove
  177. {
  178. lock (mObjectLock)
  179. {
  180. mCollectionView.CurrentChanged -= value;
  181. }
  182. }
  183. }
  184.  
  185. public event NotifyCollectionChangedEventHandler CollectionChanged
  186. {
  187. add
  188. {
  189. lock (mObjectLock)
  190. {
  191. mCollectionView.CollectionChanged += value;
  192. }
  193. }
  194. remove
  195. {
  196. lock (mObjectLock)
  197. {
  198. mCollectionView.CollectionChanged -= value;
  199. }
  200. }
  201. }
  202.  
  203. public IEnumerable<T> SourceCollectionGeneric => mCollectionView.Cast<T>();
  204. }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement