Created
March 15, 2019 11:17
-
-
Save juanch0x/1876d36223b703d4da2acf797bc53c87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.Collections.Specialized; | |
using System.ComponentModel; | |
using System.Globalization; | |
using System.Linq; | |
namespace ChequeadorDeDespiece.Base | |
{ | |
/// <summary> | |
/// Interface genérica para el uso de <see cref="T:System.ComponentModel.ICollectionView" /> de modo genérico. | |
/// </summary> | |
/// <typeparam name="T">Cualquier objeto.</typeparam> | |
public interface ICollectionView<T> : IEnumerable<T>, ICollectionView | |
{ | |
IEnumerable<T> SourceCollectionGeneric { get; } | |
} | |
public class MyCollectionViewGeneric<T> : ICollectionView<T> | |
{ | |
private readonly ICollectionView mCollectionView; | |
public MyCollectionViewGeneric(ICollectionView generic) | |
{ | |
mCollectionView = generic; | |
} | |
private class MyEnumerator : IEnumerator<T> | |
{ | |
private readonly IEnumerator mEnumerator; | |
public MyEnumerator(IEnumerator enumerator) | |
{ | |
mEnumerator = enumerator; | |
} | |
public void Dispose() | |
{ | |
} | |
public bool MoveNext() | |
{ | |
return mEnumerator.MoveNext(); | |
} | |
public void Reset() | |
{ | |
mEnumerator.Reset(); | |
} | |
public T Current => (T)mEnumerator.Current; | |
object IEnumerator.Current => Current; | |
} | |
public IEnumerator<T> GetEnumerator() | |
{ | |
return new MyEnumerator(mCollectionView.GetEnumerator()); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return mCollectionView.GetEnumerator(); | |
} | |
public bool Contains(object item) | |
{ | |
return mCollectionView.Contains(item); | |
} | |
public void Refresh() | |
{ | |
mCollectionView.Refresh(); | |
} | |
public IDisposable DeferRefresh() | |
{ | |
return mCollectionView.DeferRefresh(); | |
} | |
public bool MoveCurrentToFirst() | |
{ | |
return mCollectionView.MoveCurrentToFirst(); | |
} | |
public bool MoveCurrentToLast() | |
{ | |
return mCollectionView.MoveCurrentToLast(); | |
} | |
public bool MoveCurrentToNext() | |
{ | |
return mCollectionView.MoveCurrentToNext(); | |
} | |
public bool MoveCurrentToPrevious() | |
{ | |
return mCollectionView.MoveCurrentToPrevious(); | |
} | |
public bool MoveCurrentTo(object item) | |
{ | |
return mCollectionView.MoveCurrentTo(item); | |
} | |
public bool MoveCurrentToPosition(int position) | |
{ | |
return mCollectionView.MoveCurrentToPosition(position); | |
} | |
public CultureInfo Culture | |
{ | |
get => mCollectionView.Culture; | |
set => mCollectionView.Culture = value; | |
} | |
public IEnumerable SourceCollection => mCollectionView.SourceCollection; | |
public Predicate<object> Filter | |
{ | |
get => mCollectionView.Filter; | |
set => mCollectionView.Filter = value; | |
} | |
public bool CanFilter => mCollectionView.CanFilter; | |
public SortDescriptionCollection SortDescriptions => mCollectionView.SortDescriptions; | |
public bool CanSort => mCollectionView.CanSort; | |
public bool CanGroup => mCollectionView.CanGroup; | |
public ObservableCollection<GroupDescription> GroupDescriptions => mCollectionView.GroupDescriptions; | |
public ReadOnlyObservableCollection<object> Groups => mCollectionView.Groups; | |
public bool IsEmpty => mCollectionView.IsEmpty; | |
public object CurrentItem => mCollectionView.CurrentItem; | |
public int CurrentPosition => mCollectionView.CurrentPosition; | |
public bool IsCurrentAfterLast => mCollectionView.IsCurrentAfterLast; | |
public bool IsCurrentBeforeFirst => mCollectionView.IsCurrentBeforeFirst; | |
public event CurrentChangingEventHandler CurrentChanging | |
{ | |
add | |
{ | |
lock (mObjectLock) | |
{ | |
mCollectionView.CurrentChanging += value; | |
} | |
} | |
remove | |
{ | |
lock (mObjectLock) | |
{ | |
mCollectionView.CurrentChanging -= value; | |
} | |
} | |
} | |
private readonly object mObjectLock = new object(); | |
public event EventHandler CurrentChanged | |
{ | |
add | |
{ | |
lock (mObjectLock) | |
{ | |
mCollectionView.CurrentChanged += value; | |
} | |
} | |
remove | |
{ | |
lock (mObjectLock) | |
{ | |
mCollectionView.CurrentChanged -= value; | |
} | |
} | |
} | |
public event NotifyCollectionChangedEventHandler CollectionChanged | |
{ | |
add | |
{ | |
lock (mObjectLock) | |
{ | |
mCollectionView.CollectionChanged += value; | |
} | |
} | |
remove | |
{ | |
lock (mObjectLock) | |
{ | |
mCollectionView.CollectionChanged -= value; | |
} | |
} | |
} | |
public IEnumerable<T> SourceCollectionGeneric => mCollectionView.Cast<T>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment