2024-02-01 19:06:45 +09:00
|
|
|
|
using System;
|
2024-02-22 12:47:19 +09:00
|
|
|
|
using System.Collections.Specialized;
|
2024-02-15 17:13:16 +09:00
|
|
|
|
using R3;
|
2024-02-01 19:06:45 +09:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using ObservableCollections;
|
2024-09-03 18:54:59 +09:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2024-02-15 17:13:16 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-03 18:54:59 +09:00
|
|
|
|
// Queue <-> List Synchronization
|
|
|
|
|
var queue = new ObservableQueue<int>();
|
2024-02-15 17:13:16 +09:00
|
|
|
|
|
2024-09-03 18:54:59 +09:00
|
|
|
|
queue.Enqueue(1);
|
|
|
|
|
queue.Enqueue(10);
|
|
|
|
|
queue.Enqueue(100);
|
|
|
|
|
queue.Enqueue(1000);
|
|
|
|
|
queue.Enqueue(10000);
|
2024-02-15 17:13:16 +09:00
|
|
|
|
|
2024-09-03 18:54:59 +09:00
|
|
|
|
using var view = queue.CreateView(x => x.ToString() + "$");
|
2024-02-15 17:13:16 +09:00
|
|
|
|
|
2024-09-03 18:54:59 +09:00
|
|
|
|
using var viewList = view.ToViewList();
|
2024-02-15 17:13:16 +09:00
|
|
|
|
|
2024-09-03 18:54:59 +09:00
|
|
|
|
Console.WriteLine(viewList[2]); // 100$
|
2024-02-15 17:13:16 +09:00
|
|
|
|
|
|
|
|
|
|
2024-09-03 18:54:59 +09:00
|
|
|
|
view.ViewChanged += View_ViewChanged;
|
2021-08-04 09:30:34 +09:00
|
|
|
|
|
2024-09-03 18:54:59 +09:00
|
|
|
|
void View_ViewChanged(in SynchronizedViewChangedEventArgs<int, string> eventArgs)
|
2024-02-01 19:06:45 +09:00
|
|
|
|
{
|
2024-09-03 18:54:59 +09:00
|
|
|
|
if (eventArgs.Action == NotifyCollectionChangedAction.Add)
|
|
|
|
|
{
|
|
|
|
|
// eventArgs.OldItem.View.
|
|
|
|
|
}
|
2021-09-22 20:19:11 +09:00
|
|
|
|
|
2024-09-03 18:54:59 +09:00
|
|
|
|
throw new NotImplementedException();
|
2024-02-01 19:06:45 +09:00
|
|
|
|
}
|
2021-09-07 19:09:57 +09:00
|
|
|
|
|
2024-02-01 19:06:45 +09:00
|
|
|
|
class ViewModel
|
2021-09-22 20:19:11 +09:00
|
|
|
|
{
|
2024-02-01 19:06:45 +09:00
|
|
|
|
public int Id { get; set; }
|
2024-02-16 17:37:57 +09:00
|
|
|
|
public string Value { get; set; } = default!;
|
2021-08-04 09:30:34 +09:00
|
|
|
|
}
|
2021-09-22 20:19:11 +09:00
|
|
|
|
|
2024-08-27 23:28:30 +09:00
|
|
|
|
class HogeFilter : ISynchronizedViewFilter<int>
|
2024-02-01 19:06:45 +09:00
|
|
|
|
{
|
2024-08-27 23:28:30 +09:00
|
|
|
|
public bool IsMatch(int value)
|
2024-02-01 19:06:45 +09:00
|
|
|
|
{
|
|
|
|
|
return value % 2 == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-22 12:51:30 +09:00
|
|
|
|
public void OnCollectionChanged(in SynchronizedViewChangedEventArgs<int, ViewModel> eventArgs)
|
2024-02-01 19:06:45 +09:00
|
|
|
|
{
|
2024-02-22 12:51:30 +09:00
|
|
|
|
switch (eventArgs.Action)
|
2024-02-01 19:06:45 +09:00
|
|
|
|
{
|
2024-02-22 12:47:19 +09:00
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
2024-08-28 17:53:17 +09:00
|
|
|
|
eventArgs.NewItem.View.Value += " Add";
|
2024-02-01 19:06:45 +09:00
|
|
|
|
break;
|
2024-02-22 12:47:19 +09:00
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
2024-08-28 17:53:17 +09:00
|
|
|
|
eventArgs.OldItem.View.Value += " Remove";
|
2024-02-01 19:06:45 +09:00
|
|
|
|
break;
|
2024-02-22 12:47:19 +09:00
|
|
|
|
case NotifyCollectionChangedAction.Move:
|
2024-08-28 17:53:17 +09:00
|
|
|
|
eventArgs.NewItem.View.Value += $" Move {eventArgs.OldStartingIndex} {eventArgs.NewStartingIndex}";
|
2024-02-01 19:06:45 +09:00
|
|
|
|
break;
|
2024-02-22 12:47:19 +09:00
|
|
|
|
case NotifyCollectionChangedAction.Replace:
|
2024-08-28 17:53:17 +09:00
|
|
|
|
eventArgs.NewItem.View.Value += $" Replace {eventArgs.NewStartingIndex}";
|
2024-02-22 12:47:19 +09:00
|
|
|
|
break;
|
|
|
|
|
case NotifyCollectionChangedAction.Reset:
|
|
|
|
|
break;
|
2024-02-01 19:06:45 +09:00
|
|
|
|
default:
|
2024-02-22 12:51:30 +09:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(eventArgs.Action), eventArgs.Action, null);
|
2024-02-01 19:06:45 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|