• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

なろうブックマーク分析用ツールのPrism+WinUI3サンプル実装


Commit MetaInfo

修订版87e58c084a85279aa2ad83d3cdb09dc632aca535 (tree)
时间2022-08-25 03:24:46
作者yoshy <yoshy.org.bitbucket@gz.j...>
Commiteryoshy

Log Message

[MOD] 詳細リストの ViewComparer/ValueComparer をライブラリ側に移動

更改概述

差异

--- a/TestNarou3.Adaptor/Gateway/ViewModel/BookmarkDetailListViewModel.cs
+++ b/TestNarou3.Adaptor/Gateway/ViewModel/BookmarkDetailListViewModel.cs
@@ -1,15 +1,12 @@
11 using CleanAuLait.Core.Log;
22 using CleanAuLait.ObservableCollectionsMod;
33 using NLog;
4-using ObservableCollections;
54 using Prism.Navigation;
65 using Reactive.Bindings;
76 using Reactive.Bindings.Extensions;
8-using System.Collections.ObjectModel;
97 using System.ComponentModel;
108 using System.Diagnostics;
119 using System.Reactive.Disposables;
12-using System.Windows.Input;
1310 using TestNarou3.Adaptor.Boundary.Controller;
1411 using TestNarou3.Adaptor.Boundary.Gateway.ViewModel;
1512 using TestNarou3.Adaptor.Boundary.Gateway.ViewModel.Child;
@@ -30,8 +27,10 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel
3027
3128 public ReactiveProperty<IBookmarkDetailListRowViewModel> SelectedItem { get; }
3229
33- public INotifyCollectionChangedListSynchronizedSingleView<BookmarkDetailListRow, IBookmarkDetailListRowViewModel> Rows { get; private set; } = null;
34- private ISortableSynchronizedCoupleView<BookmarkDetailListRow, string, IBookmarkDetailListRowViewModel> SortableRows { get; set; }
30+ public INotifyCollectionChangedListSynchronizedSingleView<
31+ BookmarkDetailListRow, IBookmarkDetailListRowViewModel> Rows { get; private set; } = null;
32+ private ISortableSynchronizedCoupleView<
33+ BookmarkDetailListRow, string, IBookmarkDetailListRowViewModel> SortableRows { get; set; }
3534
3635 public ReactiveCommand CommandOpenBookmark { get; }
3736
@@ -90,7 +89,9 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel
9089 if (this.Source == null)
9190 {
9291 this.SortableRows = source.Rows
93- .ToSortableSynchronizedCoupleView(r => r.NCode, r => this.vmTranslator.Translate(r, this), new DetailListViewComparer<string>(r => r.Title.Value, true));
92+ .ToSortableSynchronizedCoupleView(
93+ r => r.NCode, r => this.vmTranslator.Translate(r, this),
94+ new DetailListViewComparer<string>(r => r.Title.Value));
9495
9596 this.Rows = this.SortableRows
9697 .ToSynchronizedSingleView()
@@ -109,19 +110,23 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel
109110 }
110111 }
111112
112- public void SortByViewColumn<TViewColumn>(string tag, Func<IBookmarkDetailListRowViewModel, TViewColumn> selector, bool ascending)
113+ public void SortByViewColumn<TViewColumn>(
114+ string tag, Func<IBookmarkDetailListRowViewModel, TViewColumn> selector, bool ascending)
113115 {
114116 logger.Trace("Sort: {0}, ascending = {1}", tag, ascending);
115- this.SortableRows.Sort(new DetailListViewComparer<TViewColumn>(selector, ascending));
117+ this.SortableRows.Sort(this.SortableRows.CreateViewComparer(selector, ascending));
116118 }
117119
118- public void SortByValueColumn<TValueColumn>(string tag, Func<BookmarkDetailListRow, TValueColumn> selector, bool ascending)
120+ public void SortByValueColumn<TValueColumn>(
121+ string tag, Func<BookmarkDetailListRow, TValueColumn> selector, bool ascending)
119122 {
120123 logger.Trace("Sort: {0}, ascending = {1}", tag, ascending);
121- this.SortableRows.Sort(new DetailListValueComparer<TValueColumn>(selector, ascending));
124+ this.SortableRows.Sort(this.SortableRows.CreateValueComparer(selector, ascending));
122125 }
123126
124- internal class DetailListViewComparer<TViewColumn> : ViewComparer<string, BookmarkDetailListRow, IBookmarkDetailListRowViewModel, TViewColumn>
127+ private class DetailListViewComparer<TViewColumn>
128+ : SortableSynchronizedCoupleViewViewComparer<
129+ string, BookmarkDetailListRow, IBookmarkDetailListRowViewModel, TViewColumn>
125130 {
126131 public DetailListViewComparer(
127132 Func<IBookmarkDetailListRowViewModel, TViewColumn> selector, bool ascending = true
@@ -130,31 +135,9 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel
130135 }
131136 }
132137
133- internal class ViewComparer<TKey, T, TView, TViewColumn> : IComparer<(TKey, T, TView)>
134- {
135- readonly Func<TView, TViewColumn> selector;
136- readonly int f;
137-
138- public ViewComparer(Func<TView, TViewColumn> selector, bool ascending = true)
139- {
140- this.selector = selector;
141- this.f = ascending ? 1 : -1;
142- }
143-
144- public int Compare((TKey, T, TView) x, (TKey, T, TView) y)
145- {
146- int c = Comparer<TViewColumn>.Default.Compare(selector(x.Item3), selector(y.Item3)) * f;
147-
148- if (c == 0)
149- {
150- c = Comparer<TKey>.Default.Compare(x.Item1, y.Item1) * f;
151- }
152-
153- return c;
154- }
155- }
156-
157- internal class DetailListValueComparer<TValueColumn> : ValueComparer<string, BookmarkDetailListRow, IBookmarkDetailListRowViewModel, TValueColumn>
138+ private class DetailListValueComparer<TValueColumn>
139+ : SortableSynchronizedCoupleViewValueComparer<
140+ string, BookmarkDetailListRow, IBookmarkDetailListRowViewModel, TValueColumn>
158141 {
159142 public DetailListValueComparer(
160143 Func<BookmarkDetailListRow, TValueColumn> selector, bool ascending = true
@@ -163,30 +146,6 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel
163146 }
164147 }
165148
166- internal class ValueComparer<TKey, T, TView, TValueColumn> : IComparer<(TKey, T, TView)>
167- {
168- readonly Func<T, TValueColumn> selector;
169- readonly int f;
170-
171- public ValueComparer(Func<T, TValueColumn> selector, bool ascending = true)
172- {
173- this.selector = selector;
174- this.f = ascending ? 1 : -1;
175- }
176-
177- public int Compare((TKey, T, TView) x, (TKey, T, TView) y)
178- {
179- int c = Comparer<TValueColumn>.Default.Compare(selector(x.Item2), selector(y.Item2)) * f;
180-
181- if (c == 0)
182- {
183- c = Comparer<TKey>.Default.Compare(x.Item1, y.Item1) * f;
184- }
185-
186- return c;
187- }
188- }
189-
190149 #endregion
191150
192151 #region IDestructible, IDisposable
@@ -213,7 +172,6 @@ namespace TestNarou3.Adaptor.Gateway.ViewModel
213172
214173 public void Dispose()
215174 {
216- // このコードを変更しないでください。クリーンアップ コードを 'Dispose(bool disposing)' メソッドに記述します
217175 Dispose(disposing: true);
218176 GC.SuppressFinalize(this);
219177 }