当前位置: 首页>>代码示例>>C#>>正文


C# TrackingCollection.SetFilter方法代码示例

本文整理汇总了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();
    }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:81,代码来源:TrackingCollectionTests.cs

示例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)));
 }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:10,代码来源:TrackingCollectionTests.cs

示例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();
    }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:57,代码来源:TrackingCollectionTests.cs


注:本文中的TrackingCollection.SetFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。