本文整理汇总了C#中TrackingCollection.SetFilter方法的典型用法代码示例。如果您正苦于以下问题:C# TrackingCollection.SetFilter方法的具体用法?C# TrackingCollection.SetFilter怎么用?C# TrackingCollection.SetFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrackingCollection
的用法示例。
在下文中一共展示了TrackingCollection.SetFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Removing
public void Removing()
{
var source = new Subject<Thing>();
var col = new TrackingCollection<Thing>(
source,
OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare,
(item, position, list) => (position > 2 && position < 5) || (position > 6 && position < 8))
{ ProcessingDelay = TimeSpan.Zero };
var count = 0;
var expectedCount = 0;
var evt = new ManualResetEvent(false);
col.Subscribe(t =>
{
if (++count == expectedCount)
evt.Set();
}, () => { });
expectedCount = 11;
Add(source, GetThing(0, 0));
Add(source, GetThing(1, 1));
Add(source, GetThing(2, 2));
Add(source, GetThing(3, 3));
Add(source, GetThing(4, 4));
Add(source, GetThing(5, 5));
Add(source, GetThing(6, 6));
Add(source, GetThing(7, 7));
Add(source, GetThing(8, 8));
Add(source, GetThing(9, 9));
Add(source, GetThing(10, 10));
evt.WaitOne();
evt.Reset();
CollectionAssert.AreEqual(col, new List<Thing> {
GetThing(3, 3),
GetThing(4, 4),
GetThing(7, 7),
});
expectedCount = 12;
col.RemoveItem(GetThing(2));
evt.WaitOne();
evt.Reset();
CollectionAssert.AreEqual(col, new List<Thing> {
GetThing(4, 4),
GetThing(5, 5),
GetThing(8, 8),
});
expectedCount = 13;
col.RemoveItem(GetThing(5));
evt.WaitOne();
evt.Reset();
CollectionAssert.AreEqual(col, new List<Thing> {
GetThing(4, 4),
GetThing(6, 6),
GetThing(9, 9),
});
col.SetFilter(null);
expectedCount = 14;
col.RemoveItem(GetThing(100)); // this one won't result in a new element from the observable
col.RemoveItem(GetThing(10));
evt.WaitOne();
evt.Reset();
Assert.AreEqual(8, col.Count);
CollectionAssert.AreEqual(col, new List<Thing> {
GetThing(0, 0),
GetThing(1, 1),
GetThing(3, 3),
GetThing(4, 4),
GetThing(6, 6),
GetThing(7, 7),
GetThing(8, 8),
GetThing(9, 9),
});
col.Dispose();
}
示例2: DisposingThrows
public void DisposingThrows()
{
var col = new TrackingCollection<Thing>(Observable.Empty<Thing>());
col.Dispose();
Assert.Throws<ObjectDisposedException>(() => col.SetFilter(null));
Assert.Throws<ObjectDisposedException>(() => col.SetComparer(null));
Assert.Throws<ObjectDisposedException>(() => col.Subscribe());
Assert.Throws<ObjectDisposedException>(() => col.AddItem(GetThing(1)));
Assert.Throws<ObjectDisposedException>(() => col.RemoveItem(GetThing(1)));
}
示例3: ChangingFilterUpdatesCollection
public void ChangingFilterUpdatesCollection()
{
var source = new Subject<Thing>();
var col = new TrackingCollection<Thing>(
source,
OrderedComparer<Thing>.OrderBy(x => x.UpdatedAt).Compare,
(item, position, list) => item.UpdatedAt < Now + TimeSpan.FromMinutes(10))
{ ProcessingDelay = TimeSpan.Zero };
var count = 0;
var expectedCount = 0;
var evt = new ManualResetEvent(false);
col.Subscribe(t =>
{
if (++count == expectedCount)
evt.Set();
}, () => { });
expectedCount = 9;
Add(source, GetThing(1, 1));
Add(source, GetThing(2, 2));
Add(source, GetThing(3, 3));
Add(source, GetThing(4, 4));
Add(source, GetThing(5, 5));
Add(source, GetThing(6, 6));
Add(source, GetThing(7, 7));
Add(source, GetThing(8, 8));
Add(source, GetThing(9, 9));
evt.WaitOne();
evt.Reset();
CollectionAssert.AreEqual(col, new List<Thing> {
GetThing(1, 1),
GetThing(2, 2),
GetThing(3, 3),
GetThing(4, 4),
GetThing(5, 5),
GetThing(6, 6),
GetThing(7, 7),
GetThing(8, 8),
GetThing(9, 9),
});
col.SetFilter((item, position, list) => item.UpdatedAt < Now + TimeSpan.FromMinutes(8));
CollectionAssert.AreEqual(col, new List<Thing> {
GetThing(1, 1),
GetThing(2, 2),
GetThing(3, 3),
GetThing(4, 4),
GetThing(5, 5),
GetThing(6, 6),
GetThing(7, 7),
});
col.Dispose();
}