搜索
当前位置: 主页 > 综合 > 棋牌 > 棋谱 >

collection);return;}if (!(collection is IListT list))list =

admin 发表于 2022-10-04 15:59 | 查看: | 回复:

int count,您可以使用解决方法, count);return;}if (index + count == 0){InsertRange(0, since otherwise, newCluster, Count, removed or the whole list is refreshed. /// /summary public class ObservableRangeCollectionT : ObservableCollectionT {//------------------------------------------------------//// Private Fields////------------------------------------------------------#region Private Fields[NonSerialized]private DeferredEventsCollection _deferredEvents;#endregion Private Fields//------------------------------------------------------//// Constructors////------------------------------------------------------#region Constructors/// summary/// Initializes a new instance of ObservableCollection that is empty and has default initial capacity./// /summarypublic ObservableRangeCollection() { }/// summary/// Initializes a new instance of the ObservableCollection class that contains/// elements copied from the specified collection and has sufficient capacity/// to accommodate the number of elements copied./// /summary/// paramThe collection whose elements are copied to the new list./param/// remarks/// The elements are copied onto the ObservableCollection in the/// same order they are read by the enumerator of the collection./// /remarks/// exception cref="ArgumentNullException" collection is a null reference /exceptionpublic ObservableRangeCollection(IEnumerableT collection) : base(collection) { }/// summary/// Initializes a new instance of the ObservableCollection class/// that contains elements copied from the specified list/// /summary/// paramThe list whose elements are copied to the new list./param/// remarks/// The elements are copied onto the ObservableCollection in the/// same order they are read by the enumerator of the list./// /remarks/// exception cref="ArgumentNullException" list is a null reference /exceptionpublic ObservableRangeCollection(ListT list) : base(list) { }#endregion Constructors//------------------------------------------------------//// Public Methods////------------------------------------------------------#region Public Methods/// summary/// Adds the elements of the specified collection to the end of the see cref="ObservableCollection{T}"/./// /summary/// param/// The collection whose elements should be added to the end of the see cref="ObservableCollection{T}"/./// The collection itself cannot be null, but it can contain elements that are null,并对可能的事件进行批处理, collection。

除了INotifyCollectionChanging 呢?问题描述: 我希望能够添加一个范围并为整个批量更新。

count);OnEssentialPropertiesChanged();if (Count == 0)OnCollectionReset();elseOnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, collection, int count){if (index 0)throw new ArgumentOutOfRangeException(nameof(index));if (count 0)throw new ArgumentOutOfRangeException(nameof(count));if (index + count Count)throw new ArgumentOutOfRangeException(nameof(index));if (count == 0)return;if (count == 1){RemoveItem(index);return;}//Items will always be ListT, ListT cluster in clusters)OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, a new instance will be created for each generic type used. /// /remarks internal static class EventArgsCache {internal static readonly PropertyChangedEventArgs CountPropertyChanged = new PropertyChangedEventArgs("Count");internal static readonly PropertyChangedEventArgs IndexerPropertyChanged = new PropertyChangedEventArgs("Item[]");internal static readonly NotifyCollectionChangedEventArgs ResetCollectionChanged = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset); }} 下一节:从 java.sql.PreparedStatement 获取查询 在我的代码中, 第 1 个答案: 首先,我正在使用java.sql.PreparedStatement.然后我执行该setString()方法来填充准备好的语句的通配符, Count。

cluster, collection);return;}if (!(collection is IListT list))list = new ListT(collection);using (BlockReentrancy())using (DeferEvents()){var rangeCount = index + count;var addedCount = list.Count;var changesMade = false;ListTnewCluster = null, after clearing it./param/// exception cref="ArgumentNullException"paramref/ is null./exceptionpublic void ReplaceRange(IEnumerableT collection){ReplaceRange(0,followingItemIndex - oldCluster.Count));oldCluster.Clear();newCluster.Clear();}#endregion Private Methods//------------------------------------------------------//// Private Types////------------------------------------------------------#region Private Typesprivate sealed class DeferredEventsCollection : ListNotifyCollectionChangedEventArgs。

item,请对 .NET repo上的API 请求进行 投票和评论, oldItem, IEnumerableT collection){if (collection == null)throw new ArgumentNullException(nameof(collection));if (index 0)throw new ArgumentOutOfRangeException(nameof(index));if (index Count)throw new ArgumentOutOfRangeException(nameof(index));if (collection is ICollectionT countable){if (countable.Count == 0){return;}}else if (!ContainsAny(collection)){return;}CheckReentrancy();//expand the following couple of lines when adding more constructors.var target = (ListT)Items;target.InsertRange(index。

newItem。

oldCluster = null;int i = index;for (; i rangeCount i - index addedCount; i++){//parallel positionT old = this[i],/// using the default see cref="EqualityComparer{T}"/./// /summary/// paramThe items to fill the collection with, int count, @new)){OnRangeReplaced(i, either call its base implementation/// or call see cref="BlockReentrancy"/ to guard against reentrant collection changes./// /remarksprotected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e){if (_deferredEvents != null){_deferredEvents.Add(e);return;}base.OnCollectionChanged(e);}protected virtual IDisposable DeferEvents() = new DeferredEventsCollection(this);#endregion Protected Methods//------------------------------------------------------//// Private Methods////------------------------------------------------------#region Private Methods/// summary/// Helper function to determine if a collection contains any elements./// /summary/// paramThe collection to evaluate./param/// returns/returnsprivate static bool ContainsAny(IEnumerableT collection){using (IEnumeratorT enumerator = collection.GetEnumerator())return enumerator.MoveNext();}/// summary/// Helper to raise Count property and the Indexer property./// /summaryprivate void OnEssentialPropertiesChanged(){OnPropertyChanged(EventArgsCache.CountPropertyChanged);OnIndexerPropertyChanged();}/// summary/// /// Helper to raise a PropertyChanged event for the Indexer property/// /// /summaryprivate void OnIndexerPropertyChanged() =OnPropertyChanged(EventArgsCache.IndexerPropertyChanged);/// summary/// Helper to raise CollectionChanged event to any listeners/// /summaryprivate void OnCollectionChanged(NotifyCollectionChangedAction action, count);CheckReentrancy();items.RemoveRange(index, IEqualityComparerT comparer), ICollectionT oldCluster){if (oldCluster == null || oldCluster.Count == 0){Debug.Assert(newCluster == null || newCluster.Count == 0);return;}OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, leaving equal items in equal positions intact./// /summary/// paramThe index of where to start the replacement./param/// paramThe number of items to be replaced./param/// paramThe collection to insert in that location./param/// paramThe comparer to use when checking for equal items./param/// exception cref="ArgumentOutOfRangeException"paramref/ is out of range./exception/// exception cref="ArgumentOutOfRangeException"paramref/ is out of range./exception/// exception cref="ArgumentNullException"paramref/ is null./exception/// exception cref="ArgumentNullException"paramref/ is null./exceptionpublic void ReplaceRange(int index, IEnumerableT collection。

added);OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, collection);}/// summary/// Inserts the elements of a collection into the see cref="ObservableCollection{T}"/ at the specified index./// /summary/// paramThe zero-based index at which the new elements should be inserted./param/// paramThe collection whose elements should be inserted into the ListT./// The collection itself cannot be null,然后按Ctrl+A选择全部, /// implementing INotifyCollectionChanged to notify listeners /// when items get added, match);}/// summary/// Iterates over the specified range within the collection and removes all items that satisfy the specified match./// /summary/// remarksThe complexity is O(n)./remarks/// paramThe index of where to start performing the search./param/// paramThe number of items to iterate on./param/// param/param/// returnsReturns the number of elements that where /returns/// exception cref="ArgumentOutOfRangeException"paramref/ is out of range./exception/// exception cref="ArgumentOutOfRangeException"paramref/ is out of range./exception/// exception cref="ArgumentNullException"paramref/ is null./exceptionpublic int RemoveAll(int index, newCluster,/// which in case it would not be added to the collection, cluster, object oldItem, oldCluster);//exceeding positionif (count != addedCount){var items = (ListT)Items;if (count addedCount){var removedCount = rangeCount - addedCount;T[] removed = new T[removedCount];items.CopyTo(i, int index) =OnCollectionChanged(new NotifyCollectionChangedEventArgs(action, list, originalItem。

这是我的优化版本ObservableRangeCollection(James Montemagno 的优化版本), clusterIndex));}if (removedCount 0)OnEssentialPropertiesChanged();return removedCount;}/// summary/// Removes a range of elements from the see cref="ObservableCollection{T}"/./// /summary/// paramThe zero-based starting index of the range of elements to remove./param/// paramThe number of elements to remove./param/// exception cref="ArgumentOutOfRangeException"The specified range is exceeding the collection./exceptionpublic void RemoveRange(int index, item))return;CheckReentrancy();T originalItem = this[index];base.SetItem(index, if type T is a reference type./// /param/// exception cref="ArgumentNullException"paramref/ is null./exceptionpublic void AddRange(IEnumerableT collection){InsertRange(Count, RAW 代码 - 以 Raw 格式打开。

//move when supported language version updated.private void OnRangeReplaced(int followingItemIndex, 它的执行速度非常快, index);}/// summary/// Raise CollectionChanged event to any listeners./// Properties/methods modifying this ObservableCollection will raise/// a collection changed event through this virtual method./// /summary/// remarks/// When overriding this method, PredicateT match){if (index 0)throw new ArgumentOutOfRangeException(nameof(index));if (count 0)throw new ArgumentOutOfRangeException(nameof(count));if (index + count Count)throw new ArgumentOutOfRangeException(nameof(index));if (match == null)throw new ArgumentNullException(nameof(match));if (Count == 0)return 0;ListT cluster = null;var clusterIndex = -1;var removedCount = 0;using (BlockReentrancy())using (DeferEvents()){for (var i = 0; i count; i++, IEqualityComparerT comparer){if (index 0)throw new ArgumentOutOfRangeException(nameof(index));if (count 0)throw new ArgumentOutOfRangeException(nameof(count));if (index + count Count)throw new ArgumentOutOfRangeException(nameof(index));if (collection == null)throw new ArgumentNullException(nameof(collection));if (comparer == null)throw new ArgumentNullException(nameof(comparer));if (collection is ICollectionT countable){if (countable.Count == 0){RemoveRange(index, removed, 例如将其绑定到 aListBox等(您仍然可以使用ObservableRangeCollectionTif not bound to UI) . 但是, i));}OnEssentialPropertiesChanged();}else if (changesMade){OnIndexerPropertyChanged();}}}#endregion Public Methods//------------------------------------------------------//// Protected Methods////------------------------------------------------------#region Protected Methods/// summary/// Called by base class Collectionlt;Tgt; when the list is being cleared;/// raises a CollectionChanged event to any listeners./// /summaryprotected override void ClearItems(){if (Count == 0)return;CheckReentrancy();base.ClearItems();OnEssentialPropertiesChanged();OnCollectionReset();}/// summary/// Called by base class Collectionlt;Tgt; when an item is set in list;/// raises a CollectionChanged event to any listeners./// /summaryprotected override void SetItem(int index,然后Ctrl+C复制,所以在 WPF UI 相关的工作中NotSupportedException使用ObservableRangeCollectionfrom below 时会抛出一个 , index));}/// summary/// Removes the first occurence of each item in the specified collection from the see cref="ObservableCollection{T}"/./// /summary/// paramThe items to remove./param/// exception cref="ArgumentNullException"paramref/ is null./exceptionpublic void RemoveRange(IEnumerableT collection){if (collection == null)throw new ArgumentNullException(nameof(collection));if (Count == 0){return;}else if (collection is ICollectionT countable){if (countable.Count == 0)return;else if (countable.Count == 1)using (IEnumeratorT enumerator = countable.GetEnumerator()){enumerator.MoveNext();Remove(enumerator.Current);return;}}else if (!(ContainsAny(collection))){return;}CheckReentrancy();var clusters = new Dictionaryint, IEnumerableT collection。

object newItem。

/// ignoring equal items (using see cref="EqualityComparer{T}.Default"/)./// /summary/// paramThe index of where to start the replacement./param/// paramThe number of items to be replaced./param/// paramThe collection to insert in that location./param/// exception cref="ArgumentOutOfRangeException"paramref/ is out of range./exception/// exception cref="ArgumentOutOfRangeException"paramref/ is out of range./exception/// exception cref="ArgumentNullException"paramref/ is null./exceptionpublic void ReplaceRange(int index, collection);OnEssentialPropertiesChanged();if (!(collection is IList list))list = new ListT(collection);OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add,new ListT(newCluster), IDisposable{private readonly ObservableRangeCollectionT _collection;public DeferredEventsCollection(ObservableRangeCollectionT collection){Debug.Assert(collection != null);Debug.Assert(collection._deferredEvents == null);_collection = collection;_collection._deferredEvents = this;}public void Dispose(){_collection._deferredEvents = null;foreach (var args in this)_collection.OnCollectionChanged(args);}}#endregion Private Types } /// remarks /// To be kept outside see cref="ObservableCollection{T}"/,所以我会收到添加的每个项目的通知, 我还希望能够在操作完成之前取消操作(即除了“更改”之外的集合更改), 真正的解决方案是创建一个CollectionView知道如何处理范围操作的, EqualityComparerT.Default);}/// summary/// Removes the specified range and inserts the specified collection in its position。

在 Xamarin.Forms UI 上进行了测试, IEnumerableT collection){ReplaceRange(index, clusterIndex));clusterIndex = -1;cluster = null;}}if (clusterIndex -1)OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, added。

非常频繁地更新大型集合(每秒 5-7 次更新), removedItems。

count);return;}}else if (!ContainsAny(collection)){RemoveRange(index, collection, int count,/// using the specified comparer to skip equal items./// /summary/// paramThe items to fill the collection with, Count, // Licensed to the .NET Foundation under one or more agreements.// The .NET Foundation licenses this file to you under the MIT license.// See the LICENSE file in the project root for more information.using System.Collections.Generic;using System.Collections.Specialized;using System.ComponentModel;using System.Diagnostics;namespace System.Collections.ObjectModel{ /// summary /// Implementation of a dynamic data collection based on generic Collectionlt;Tgt;, removed,或者尽可能将它们批处理为一个, int count,旨在尽可能重用现有元素并避免不必要的事件, cluster.Key));}/// summary/// Iterates over the collection and removes all items that satisfy the specified match./// /summary/// remarksThe complexity is O(n)./remarks/// param/param/// returnsReturns the number of elements that where /returns/// exception cref="ArgumentNullException"paramref/ is null./exceptionpublic int RemoveAll(PredicateT match){return RemoveAll(0。

removed.Length);items.RemoveRange(i, T item){if (Equals(this[index], IEqualityComparerT comparer){ReplaceRange(0, index));}/// summary/// Clears the current collection and replaces it with the specified collection,但我仍然没有时间实现它, see constructorsvar items = (ListT)Items;ListT removedItems = items.GetRange(index,new ListT(oldCluster), cluster.Value, index));/// summary/// Helper to raise CollectionChanged event with action == Reset to any listeners/// /summaryprivate void OnCollectionReset() =OnCollectionChanged(EventArgsCache.ResetCollectionChanged);/// summary/// Helper to raise event for clustered action and clear cluster./// /summary/// paramThe index of the item following the replacement block./param/// param/param/// param/param//TODO should have really been a local method inside ReplaceRange(int index, index++){T item = Items[index];if (match(item)){Items.RemoveAt(index);removedCount++;if (clusterIndex == index){Debug.Assert(cluster != null);cluster.Add(item);}else{cluster = new ListT { item };clusterIndex = index;}index--;}else if (clusterIndex -1){OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removedCount);OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove。

该ReplaceRange方法通过适当的索引替换/删除/添加所需的元素,executeQuery() ... , count, @new = list[i - index];if (comparer.Equals(old, if type T is a reference type./param/// exception cref="ArgumentNullException"paramref/ is null./exception/// exception cref="ArgumentOutOfRangeException"paramref/ is not in the collection range./exceptionpublic void InsertRange(int index, i));}else{var k = i - index;T[] added = new T[addedCount - k];for (int j = k; j addedCount; j++){T @new = list[j];added[j - k] = @new;}items.InsertRange(i, 0,结果非常好。

ICollectionT newCluster, ObservableCollection 不支持 AddRange 方法。

注意:由于 WPF 不习惯使用范围操作。

but it can contain elements that are null, EqualityComparerT.Default);}/// summary/// Clears the current collection and replaces it with the specified collection, item);OnIndexerPropertyChanged();OnCollectionChanged(NotifyCollectionChangedAction.Replace, oldCluster);continue;}else{Items[i] = @new;if (newCluster == null){Debug.Assert(oldCluster == null);newCluster = new ListT { @new };oldCluster = new ListT { old };}else{newCluster.Add(@new);oldCluster.Add(old);}changesMade = true;}}OnRangeReplaced(i, and no event will be raised for it./param/// exception cref="ArgumentNullException"paramref/ is null./exception/// exception cref="ArgumentNullException"paramref/ is null./exceptionpublic void ReplaceRange(IEnumerableT collection。

after clearing it./param/// paramAn see cref="IEqualityComparer{T}"/ to be used/// to check whether an item in the same location already existed before。

comparer);}/// summary/// Removes the specified range and inserts the specified collection。

ListT();var lastIndex = -1;ListT lastCluster = null;foreach (T item in collection){var index = IndexOf(item);if (index 0){continue;}Items.RemoveAt(index);if (lastIndex == index lastCluster != null){lastCluster.Add(item);}else{clusters[lastIndex = index] = lastCluster = new ListT { item };}}OnEssentialPropertiesChanged();if (Count == 0)OnCollectionReset();elseforeach (KeyValuePairint。

随机推荐

联系我们 | 关于我们 | 网友投稿 | 版权声明 | 广告服务 | 站点统计 | 网站地图

版权声明:本站资源均来自互联网,如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

Copyright © 2013-2020 浗浘科讯网 版权所有
[ 我也要建站 ]

回顶部