本文整理汇总了C#中ObservableCollection.ToQueryable方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.ToQueryable方法的具体用法?C# ObservableCollection.ToQueryable怎么用?C# ObservableCollection.ToQueryable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.ToQueryable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Result_is_updated_after_Insert
public void Result_is_updated_after_Insert()
{
var subject = new ObservableCollection<int>(new [] { 10, 11, 12, 11, 12, 10, 12, 17 });
var result = subject.ToQueryable().Distinct().ToObservable();
var eventList = new List<NotifyCollectionChangedEventArgs>();
result.CollectionChanged += (s, e) => eventList.Add(e);
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
subject.Insert(2, 10);
EnumerableAssert.AreEqual(result, 10, 11, 12, 17);
Assert.AreEqual(0, eventList.Count);
subject.Insert(1, 11);
EnumerableAssert.AreEqual(result, 10, 11, 12, 17);
Assert.AreEqual(0, eventList.Count);
subject.Insert(1, 12);
EnumerableAssert.AreEqual(result, 10, 12, 11, 17);
Assert.AreEqual(1, eventList.Count);
Assert.AreEqual(NotifyCollectionChangedAction.Move, eventList.Last().Action);
subject.Insert(0, 17);
EnumerableAssert.AreEqual(result, 17, 10, 12, 11);
Assert.AreEqual(2, eventList.Count);
Assert.AreEqual(NotifyCollectionChangedAction.Move, eventList.Last().Action);
}
示例2: Result_is_updated_after_Move
public void Result_is_updated_after_Move()
{
var subject = new ObservableCollection<int>(new [] { 10, 11, 12, 11, 12, 10, 12, 17 });
var result = subject.ToQueryable().Distinct().ToObservable();
var expected = subject.Distinct();
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
var events = new Queue<NotifyCollectionChangedEventArgs>();
result.CollectionChanged += (s, e) => events.Enqueue(e);
subject.Move(4, 7);
expected = subject.Distinct();
EnumerableAssert.AreEqual(result, expected);
Assert.AreEqual(0, events.Count);
subject.Move(3, 0);
expected = subject.Distinct();
EnumerableAssert.AreEqual(result, expected);
Assert.AreEqual(NotifyCollectionChangedAction.Move, events.Dequeue().Action);
subject.Move(2, 1);
expected = subject.Distinct();
EnumerableAssert.AreEqual(result, expected);
Assert.AreEqual(0, events.Count);
subject.Move(5, 1);
expected = subject.Distinct();
EnumerableAssert.AreEqual(result, expected);
Assert.AreEqual(NotifyCollectionChangedAction.Move, events.Dequeue().Action);
}
示例3: Select_Is_Updated_On_Add
public void Select_Is_Updated_On_Add()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 3, 4, 5, 6, 7 });
var result = subject.ToQueryable().Select(i => i * 2).ToObservable();
subject.Add(8);
Assert.AreEqual(16, result[8]);
}
示例4: Result_updated_after_Add
public void Result_updated_after_Add()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 3, 4, 5, 6, 7 });
var result = subject.ToQueryable().Where(i => i % 2 == 0).ToObservable();
subject.Add(8);
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
Assert.AreEqual(0, result[0]);
Assert.AreEqual(2, result[1]);
Assert.AreEqual(4, result[2]);
Assert.AreEqual(6, result[3]);
Assert.AreEqual(8, result[4]);
Assert.AreEqual(5, result.Count);
subject.Add(9);
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
Assert.AreEqual(0, result[0]);
Assert.AreEqual(2, result[1]);
Assert.AreEqual(4, result[2]);
Assert.AreEqual(6, result[3]);
Assert.AreEqual(8, result[4]);
Assert.AreEqual(5, result.Count);
}
示例5: Result_is_correct_initially
public void Result_is_correct_initially()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 1, 2, 0, 2, 7 });
var result = subject.ToQueryable().Distinct().ToObservable();
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
EnumerableAssert.AreEqual(result, 0, 1, 2, 7);
}
示例6: Initial_Select_Is_Correct
public void Initial_Select_Is_Correct()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 3, 4, 5, 6, 7 });
var result = subject.ToQueryable().Select(i => i * 2).ToObservable();
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
Assert.AreEqual(0, result[0]);
Assert.AreEqual(14, result[7]);
}
示例7: Select_Is_Updated_On_Remove
public void Select_Is_Updated_On_Remove()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 3, 4, 5, 6, 7 });
var result = subject.ToQueryable().Select(i => i * 2).ToObservable();
subject.Remove(5);
Assert.AreEqual(12, result[5]);
subject.RemoveAt(5);
Assert.AreEqual(14, result[5]);
}
示例8: Select_Is_Updated_On_Replace
public void Select_Is_Updated_On_Replace()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 3, 4, 5, 6, 7 });
var result = subject.ToQueryable().Select(i => i * 2).ToObservable();
subject[3] = 8;
Assert.AreEqual(4, result[2]);
Assert.AreEqual(16, result[3]);
Assert.AreEqual(8, result[4]);
}
示例9: Result_is_filtered_initially
public void Result_is_filtered_initially()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 3, 4, 5, 6, 7 });
var result = subject.ToQueryable().Where(i => i % 2 == 0).ToObservable();
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
Assert.AreEqual(0, result[0]);
Assert.AreEqual(2, result[1]);
Assert.AreEqual(4, result[2]);
Assert.AreEqual(6, result[3]);
Assert.AreEqual(4, result.Count);
}
示例10: Result_is_correct_initially
public void Result_is_correct_initially()
{
var subject = new ObservableCollection<int>(new [] { 1, 2, 5, 6, 7, 0, 3, 4 });
var result = subject.ToQueryable().OrderBy(i => i).ToObservable();
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
Assert.AreEqual(0, result[0]);
Assert.AreEqual(2, result[2]);
Assert.AreEqual(4, result[4]);
Assert.AreEqual(6, result[6]);
Assert.AreEqual(8, result.Count);
}
示例11: Result_is_updated_after_Add
public void Result_is_updated_after_Add()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 1, 2, 0, 2, 7 });
var result = subject.ToQueryable().Distinct().ToObservable();
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
subject.Add(0);
EnumerableAssert.AreEqual(result, 0, 1, 2, 7);
subject.Add(1);
EnumerableAssert.AreEqual(result, 0, 1, 2, 7);
subject.Add(2);
EnumerableAssert.AreEqual(result, 0, 1, 2, 7);
subject.Add(7);
EnumerableAssert.AreEqual(result, 0, 1, 2, 7);
subject.Add(6);
EnumerableAssert.AreEqual(result, 0, 1, 2, 7, 6);
}
示例12: Result_is_updated_after_Insert
public void Result_is_updated_after_Insert()
{
var subject = new ObservableCollection<int>(new [] { 1, 2, 6, 4 });
var result = subject.ToQueryable().OrderBy(i => i).ToObservable();
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
subject.Insert(1, 10);
Assert.AreEqual(1, result[0]);
Assert.AreEqual(2, result[1]);
Assert.AreEqual(4, result[2]);
Assert.AreEqual(6, result[3]);
Assert.AreEqual(10, result[4]);
Assert.AreEqual(5, result.Count);
subject.Insert(3, -1);
Assert.AreEqual(-1, result[0]);
Assert.AreEqual(1, result[1]);
Assert.AreEqual(2, result[2]);
Assert.AreEqual(4, result[3]);
Assert.AreEqual(6, result[4]);
Assert.AreEqual(10, result[5]);
Assert.AreEqual(6, result.Count);
subject.Insert(4, 7);
Assert.AreEqual(-1, result[0]);
Assert.AreEqual(1, result[1]);
Assert.AreEqual(2, result[2]);
Assert.AreEqual(4, result[3]);
Assert.AreEqual(6, result[4]);
Assert.AreEqual(7, result[5]);
Assert.AreEqual(10, result[6]);
Assert.AreEqual(7, result.Count);
}
示例13: Result_is_updated_after_Add
public void Result_is_updated_after_Add()
{
var subject = new ObservableCollection<int>(new [] { 1, 2, 6, 6, 7, 0, 3, 4 });
var result = subject.ToQueryable().OrderBy(i => i).ToObservable();
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
subject.Add(9);
Assert.AreEqual(0, result[0]);
Assert.AreEqual(2, result[2]);
Assert.AreEqual(4, result[4]);
Assert.AreEqual(6, result[6]);
Assert.AreEqual(9, result[8]);
Assert.AreEqual(9, result.Count);
subject.Add(8);
Assert.AreEqual(0, result[0]);
Assert.AreEqual(2, result[2]);
Assert.AreEqual(4, result[4]);
Assert.AreEqual(6, result[6]);
Assert.AreEqual(8, result[8]);
Assert.AreEqual(9, result[9]);
Assert.AreEqual(10, result.Count);
subject.Add(5);
Assert.AreEqual(0, result[0]);
Assert.AreEqual(2, result[2]);
Assert.AreEqual(4, result[4]);
Assert.AreEqual(6, result[6]);
Assert.AreEqual(7, result[8]);
Assert.AreEqual(8, result[9]);
Assert.AreEqual(9, result[10]);
Assert.AreEqual(11, result.Count);
}
示例14: Find_element
public void Find_element()
{
var subject = new ObservableCollection<int>(new [] { 1, 2, 6, 6, 7, 0, 3, 4 });
var result = subject.ToQueryable().OrderBy(i => i).ToObservable();
var firstPosition = result.BinarySearch(0, i => i);
Assert.AreEqual(0, firstPosition.Index);
Assert.AreEqual(0, firstPosition.Offset);
var beforeFirstPosition = result.BinarySearch(-1, i => i);
Assert.AreEqual(-1, beforeFirstPosition.Index);
Assert.AreEqual(1, beforeFirstPosition.Offset);
var lastPosition = result.BinarySearch(7, i => i);
Assert.AreEqual(7, lastPosition.Index);
Assert.AreEqual(0, lastPosition.Offset);
var afterLastPosition = result.BinarySearch(17, i => i);
Assert.AreEqual(7, afterLastPosition.Index);
Assert.AreEqual(1, afterLastPosition.Offset);
var middlePosition = result.BinarySearch(3, i => i);
Assert.AreEqual(3, middlePosition.Index);
Assert.AreEqual(0, middlePosition.Offset);
var missingPosition = result.BinarySearch(5, i => i);
Assert.AreEqual(4, missingPosition.Index);
Assert.AreEqual(1, missingPosition.Offset);
}
示例15: Cannot_change_filtered
public void Cannot_change_filtered()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 3, 4, 5, 6, 7 });
subject.ToQueryable().Where(x => x / 2 == 0).ToObservable().Add(10);
}