System.Predicate.Invoke(T)

Here are the examples of the csharp api System.Predicate.Invoke(T) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

517 Examples 7

19 View Source File : Helpers.cs
License : MIT License
Project Creator : 0x1000000

public static IReadOnlyList<TRes> SelectToReadOnlyList<T, TRes>(this IReadOnlyList<T> source, Predicate<T> predicate, Func<T, TRes> mapper)
        {
            source.replacedertNotNull($"\"{nameof(source)}\" cannot be null");
            mapper.replacedertNotNull($"\"{nameof(mapper)}\" cannot be null");
            predicate.replacedertNotNull($"\"{nameof(predicate)}\" cannot be null");

            int count = 0;

            for (int i = 0; i < source.Count; i++)
            {
                if (predicate(source[i]))
                {
                    count++;
                }
            }

            TRes[] result = new TRes[count];
            if (count > 0)
            {
                int resultIndex = 0;
                for (int i = 0; i < source.Count; i++)
                {
                    if (predicate(source[i]))
                    {
                        if (resultIndex >= result.Length)
                        {
                            throw new SqExpressException("The predicate function should be idempotent",
                                new IndexOutOfRangeException());
                        }

                        result[resultIndex] = mapper(source[i]);
                        resultIndex++;
                    }
                }

                if (resultIndex != result.Length)
                {
                    throw new SqExpressException("The predicate function should be idempotent");
                }
            }
            return result;
        }

19 View Source File : MainWindow_Model.cs
License : MIT License
Project Creator : 1217950746

public bool CanExecute(object parameter)
        {
            return _canExecute == null || _canExecute((T)parameter);
        }

19 View Source File : LinkedList.Extension.cs
License : MIT License
Project Creator : 7Bytes-Studio

public static bool Contains<T>(this LinkedList<T> linkedList,Predicate<T> predicate)
        {
            var current = linkedList.First;
            while (null!=current)
            {
                if (predicate.Invoke(current.Value))
                {
                    return true;
                }
                current = current.Next;
            }
            return false;
        }

19 View Source File : LinkedList.Extension.cs
License : MIT License
Project Creator : 7Bytes-Studio

public static T Find<T>(this LinkedList<T> linkedList,Predicate<T> predicate)
        {
            var current = linkedList.First;
            while (null!=current)
            {
                if (predicate.Invoke(current.Value))
                {
                    return current.Value;
                }
                current = current.Next;
            }
            return default(T);
        }

19 View Source File : FastList.cs
License : MIT License
Project Creator : absurd-joy

public T Find(Predicate<T> match) {
        if (match != null) {
            if (array != null) {
                for (int i = 0; i < size; i++) {
                    if (match(array[i])) { return array[i];}
                }
            }
        }
        return default(T);
    }

19 View Source File : RelayCommand{T}.cs
License : MIT License
Project Creator : Accelerider

public bool CanExecute(T parameter)
        {
            return _canExecute?.Invoke(parameter) ?? true;
        }

19 View Source File : EnumerableExtensions.cs
License : MIT License
Project Creator : actions

public static ParreplacedionResults<T> Parreplacedion<T>(this IEnumerable<T> source, Predicate<T> predicate)
        {
            ArgumentUtility.CheckForNull(source, nameof(source));
            ArgumentUtility.CheckForNull(predicate, nameof(predicate));

            var results = new ParreplacedionResults<T>();

            foreach (var item in source)
            {
                if (predicate(item))
                {
                    results.MatchingParreplacedion.Add(item);
                }
                else
                {
                    results.NonMatchingParreplacedion.Add(item);
                }
            }

            return results;
        }

19 View Source File : EnumerableExtensions.cs
License : MIT License
Project Creator : actions

public static MultiParreplacedionResults<T> Parreplacedion<T>(this IEnumerable<T> source, params Predicate<T>[] predicates)
        {
            ArgumentUtility.CheckForNull(source, nameof(source));
            ArgumentUtility.CheckForNull(predicates, nameof(predicates));

            var range = Enumerable.Range(0, predicates.Length).ToList();

            var results = new MultiParreplacedionResults<T>();
            results.MatchingParreplacedions.AddRange(range.Select(_ => new List<T>()));

            foreach (var item in source)
            {
                bool added = false;

                foreach (var predicateIndex in range.Where(predicateIndex => predicates[predicateIndex](item)))
                {
                    results.MatchingParreplacedions[predicateIndex].Add(item);
                    added = true;
                    break;
                }

                if (!added)
                {
                    results.NonMatchingParreplacedion.Add(item);
                }
            }

            return results;
        }

19 View Source File : EnumerableExtensions.cs
License : MIT License
Project Creator : actions

public static IList<P> ParreplacedionSolveAndMergeBack<T, P>(this IList<T> source, Predicate<T> predicate, Func<IList<T>, IList<P>> matchingParreplacedionSolver, Func<IList<T>, IList<P>> nonMatchingParreplacedionSolver)
        {
            ArgumentUtility.CheckForNull(source, nameof(source));
            ArgumentUtility.CheckForNull(predicate, nameof(predicate));
            ArgumentUtility.CheckForNull(matchingParreplacedionSolver, nameof(matchingParreplacedionSolver));
            ArgumentUtility.CheckForNull(nonMatchingParreplacedionSolver, nameof(nonMatchingParreplacedionSolver));

            var parreplacedionedSource = new ParreplacedionResults<Tuple<int, T>>();

            for (int sourceCnt = 0; sourceCnt < source.Count; sourceCnt++)
            {
                var item = source[sourceCnt];

                if (predicate(item))
                {
                    parreplacedionedSource.MatchingParreplacedion.Add(new Tuple<int, T>(sourceCnt, item));
                }
                else
                {
                    parreplacedionedSource.NonMatchingParreplacedion.Add(new Tuple<int, T>(sourceCnt, item));
                }
            }

            var solvedResult = new List<P>(source.Count);
            if (parreplacedionedSource.MatchingParreplacedion.Any())
            {
                solvedResult.AddRange(matchingParreplacedionSolver(parreplacedionedSource.MatchingParreplacedion.Select(x => x.Item2).ToList()));
            }

            if (parreplacedionedSource.NonMatchingParreplacedion.Any())
            {
                solvedResult.AddRange(nonMatchingParreplacedionSolver(parreplacedionedSource.NonMatchingParreplacedion.Select(x => x.Item2).ToList()));
            }

            var result = Enumerable.Repeat(default(P), source.Count).ToList();

            if (solvedResult.Count != source.Count)
            {
                return solvedResult; // either we can throw here or just return solvedResult and ignore!
            }

            for (int resultCnt = 0; resultCnt < source.Count; resultCnt++)
            {
                if (resultCnt < parreplacedionedSource.MatchingParreplacedion.Count)
                {
                    result[parreplacedionedSource.MatchingParreplacedion[resultCnt].Item1] = solvedResult[resultCnt];
                }
                else
                {
                    result[parreplacedionedSource.NonMatchingParreplacedion[resultCnt - parreplacedionedSource.MatchingParreplacedion.Count].Item1] = solvedResult[resultCnt];
                }
            }

            return result;
        }

19 View Source File : PostFilterPaginator.cs
License : MIT License
Project Creator : Adoxio

private void Select(int offset, int limit, int itemLimit, ICollection<T> items)
		{
			var selected = _select(offset, limit);

			foreach (var item in selected)
			{
				offset++;

				if (!_filter(item))
				{
					continue;
				}

				items.Add(item);

				if (items.Count >= itemLimit)
				{
					return;
				}
			}

			// If _select returned fewer items than were asked for, there must be no further items
			// to select, and so we should quit after processing the items we did get.
			if (selected.Length < limit)
			{
				return;
			}

			// For the next selection, set the limit to the median value between the original query
			// limit, and the number of remaining items needed.
			var reselectLimit = Convert.ToInt32(Math.Round((limit + (itemLimit - items.Count)) / 2.0, MidpointRounding.AwayFromZero));

			Select(offset, reselectLimit, itemLimit, items);
		}

19 View Source File : TopPaginator.cs
License : MIT License
Project Creator : Adoxio

private int Gereplacedems(int topLimit, int unfilteredItemOffset, int itemLimit, ICollection<T> items)
		{
			var top = _getTop(topLimit);

			if (unfilteredItemOffset >= top.TotalUnfilteredItems)
			{
				return top.TotalUnfilteredItems;
			}

			foreach (var item in top.Skip(unfilteredItemOffset))
			{
				unfilteredItemOffset++;

				if (!_selector(item))
				{
					continue;
				}

				items.Add(item);

				if (items.Count >= itemLimit)
				{
					return top.TotalUnfilteredItems;
				}
			}

			if (topLimit >= top.TotalUnfilteredItems)
			{
				return items.Count;
			}

			return Gereplacedems(topLimit * _extendedSearchLimitMultiple, unfilteredItemOffset, itemLimit, items);
		}

19 View Source File : RelayCommand.cs
License : MIT License
Project Creator : afxw

public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute((T)parameter);
        }

19 View Source File : MemoryAiurStoreDb.cs
License : MIT License
Project Creator : AiursoftWeb

private LinkedListNode<T> SearchFromLast(Predicate<T> prefix)
        {
            var last = _store.Last;
            while (last != null)
            {
                if (prefix(last.Value))
                {
                    return last;
                }
                last = last.Previous;
            }
            throw new InvalidOperationException("Result not found.");
        }

19 View Source File : OrderedList.cs
License : GNU General Public License v3.0
Project Creator : alexgracianoarj

public bool RemoveOn(Predicate<T> match)
		{
			LinkedListNode<T> current = First;
			while (current != null)
			{
				if (match(current.Value))
				{
					this.Remove(current);
					return true;
				}
				current = current.Next;
			}
			return false;
		}

19 View Source File : Tool.cs
License : Apache License 2.0
Project Creator : Algoryx

public T FindActive<T>( Predicate<T> pred ) where T : Tool
    {
      if ( this is T && pred( this as T ) )
        return this as T;

      foreach ( var child in m_children ) {
        var result = child.FindActive( pred );
        if ( result != null )
          return result;
      }

      return null;
    }

19 View Source File : ObjectDb.cs
License : Apache License 2.0
Project Creator : Algoryx

public T GetOrCreatereplacedet<T>( System.Predicate<T> predicate,
                                  string name,
                                  System.Action<T> onFirstRef )
      where T : ScriptableObject
    {
      if ( predicate == null )
        throw new System.ArgumentNullException( "predicate" );

      var replacedets = Getreplacedets<T>();
      T alreadyCreatedreplacedet = null;
      foreach ( var replacedet in replacedets ) {
        if ( predicate( replacedet ) ) {
          alreadyCreatedreplacedet = replacedet;
          break;
        }
      }

      return GetOrCreatereplacedet( alreadyCreatedreplacedet, name, onFirstRef );
    }

19 View Source File : CustomExtensions.cs
License : MIT License
Project Creator : andruzzzhka

public static int FindIndexInArray<T>(this T[] list, Predicate<T> predicate)
        {
            for (int i = 0; i < list.Length; i++)
            {
                if (predicate(list[i]))
                    return i;
            }
            return -1;
        }

19 View Source File : Utils.cs
License : MIT License
Project Creator : ansel86castro

public static LinkedListNode<T> GetLinkedNode<T>(this LinkedList<T> list, Predicate<T> condition)
        {
            LinkedListNode<T> node = null;
            LinkedListNode<T> current = list.First;
            while (current != null)
            {
                if (condition(current.Value))
                {
                    node = current;
                    break;
                }
                current = current.Next;
            }
            return node;
        }

19 View Source File : RelayCommand.cs
License : MIT License
Project Creator : arasplm

public bool CanExecute(object parameter)
		{
			return canExecute == null ? true : canExecute((T)parameter);
		}

19 View Source File : EnumerableBenchmarks.cs
License : MIT License
Project Creator : asc-community

public static IEnumerable<T> CustomWhere<T>(this T[] ienumerable, Predicate<T> where)
		{
			foreach (T value in ienumerable)
			{
				if (where(value))
				{
					yield return value;
				}
			}
		}

19 View Source File : CheckExtensions.cs
License : Apache License 2.0
Project Creator : atata-framework

internal static T Check<T>(this T value, Predicate<T> checkPredicate, string argumentName, string errorMessage)
        {
            if (checkPredicate != null && !checkPredicate(value))
                throw new ArgumentException(errorMessage, argumentName);

            return value;
        }

19 View Source File : LinqExtensions.cs
License : Apache License 2.0
Project Creator : AutomateThePlanet

public static int IndexOf<T>(this IEnumerable<T> list, Predicate<T> condition)
        {
            int i = -1;
            return list.Any(x =>
            {
                i++;
                return condition(x);
            }) ? i : -1;
        }

19 View Source File : Check.cs
License : MIT License
Project Creator : Avanade

public static T IsTrue<T>(T value, Predicate<T> predicate, string? message = null)
        {
            if (predicate == null || predicate(value))
                return value;

            throw new ArgumentException(message ?? "Argument is not valid.");
        }

19 View Source File : Check.cs
License : MIT License
Project Creator : Avanade

public static T IsFalse<T>(T value, Predicate<T> predicate, string? message = null)
        {
            if (predicate == null || !predicate(value))
                return value;

            throw new ArgumentException(message ?? "Argument is not valid.");
        }

19 View Source File : Check.cs
License : MIT License
Project Creator : Avanade

public static T IsValid<T>(T value, Predicate<T> predicate, string? message = null)
        {
            if (predicate == null || predicate(value))
                return value;

            throw new InvalidOperationException(message ?? "Operation is not valid.");
        }

19 View Source File : TreeNode.cs
License : MIT License
Project Creator : Avatarchik

public TreeNode<T> FindChild(Predicate<T> match)
        {
            if (match(value)) return this;

            if (_firstChild != null)
            {
                var node = _firstChild;
                TreeNode<T> result;

                do
                {
                    result = node.FindChild(match);
                    if (result != null) return result;
                    node = node._next;
                }
                while (node != _firstChild);
            }

            return null;
        }

19 View Source File : TreeNode.cs
License : MIT License
Project Creator : Avatarchik

public TreeNode<T> FindParent(Predicate<T> match)
        {
            var node = this;

            do
            {
                if (match(node.value)) return node;
                node = node._parent;
            }
            while (node != null);

            return null;
        }

19 View Source File : TreeNode.cs
License : MIT License
Project Creator : Avatarchik

public TreeNode<T> FindDirectChildren(Predicate<T> match)
        {
            var node = _firstChild;
            while (node != null)
            {
                if (match(node.value)) return node;
                node = node.next;
            }
            return null;
        }

19 View Source File : UntilResponseFailurePoller.cs
License : Apache License 2.0
Project Creator : aws

public async Task<T> Poll<T>(int periodMs, Func<T> action, Predicate<T> stopCondition = null) where T : Response
        {
            if (action is null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            T response;

            while (true)
            {
                response = action();

                if (!response.Success)
                {
                    break;
                }

                if (stopCondition != null && stopCondition(response))
                {
                    break;
                }

                await Task.Delay(periodMs);
            }

            return response;
        }

19 View Source File : ChainedEvent.cs
License : GNU Lesser General Public License v2.1
Project Creator : axiom3d

public virtual bool Fire(object sender, T arg, Predicate<T> compare)
        {
            var continueChain = true;

            // replaceduming the multicast delegate is not null...
            if (this.EventSinks != null)
            {
                // Call the methods until one of them handles the event
                // or all the methods in the delegate list are processed.
                foreach (EventHandler<T> sink in this.EventSinks.GetInvocationList())
                {
                    sink(sender, arg);
                    continueChain = compare(arg);
                    if (!continueChain)
                    {
                        break;
                    }
                }
            }
            // Return a flag indicating whether an event sink canceled the event.
            return continueChain;
        }

19 View Source File : HashSet.cs
License : GNU Lesser General Public License v2.1
Project Creator : axiom3d

public int RemoveWhere(Predicate<T> match)
        {
            if (match == null)
                throw new ArgumentNullException("match");

            var candidates = new List<T>();

            foreach (var item in this)
                if (match(item))
                    candidates.Add(item);

            foreach (var item in candidates)
                Remove(item);

            return candidates.Count;
        }

19 View Source File : System.Collections.cs
License : GNU Lesser General Public License v2.1
Project Creator : axiom3d

public static int RemoveAll<T>(this List<T> list, Predicate<T> match)
            {
                var count = list.Count;
                var currentIdx = 0;
                var i = 0;
                while (i++ < count)
                    if (match(list[currentIdx])) list.RemoveAt(currentIdx);
                    else currentIdx++;
                return currentIdx;
            }

19 View Source File : Debug.cs
License : MIT License
Project Creator : ay2015

[Conditional("DEBUG")]
        public static void IsTrue<T>(Predicate<T> predicate, T arg)
        {
            if (!predicate(arg))
            {
                _Break();
            }
        }

19 View Source File : UnmanagedList.cs
License : MIT License
Project Creator : b-editor

public T? Find(Predicate<T> match)
        {
            if (match is null) throw new ArgumentNullException(nameof(match));

            for (var i = 0; i < _size; i++)
            {
                if (match(_items[i]))
                {
                    return _items[i];
                }
            }

            return default;
        }

19 View Source File : UnmanagedList.cs
License : MIT License
Project Creator : b-editor

public UnmanagedList<T> FindAll(Predicate<T> match)
        {
            if (match is null) throw new ArgumentNullException(nameof(match));

            var list = new UnmanagedList<T>();
            for (var i = 0; i < _size; i++)
            {
                if (match(_items[i]))
                {
                    list.Add(_items[i]);
                }
            }

            return list;
        }

19 View Source File : UnmanagedList.cs
License : MIT License
Project Creator : b-editor

public int FindIndex(int startIndex, int count, Predicate<T> match)
        {
            if ((uint)startIndex > (uint)_size) throw new ArgumentOutOfRangeException(nameof(startIndex));
            if (count < 0 || startIndex > _size - count) throw new ArgumentOutOfRangeException(nameof(count));
            if (match is null) throw new ArgumentNullException(nameof(match));

            var endIndex = startIndex + count;
            for (var i = startIndex; i < endIndex; i++)
            {
                if (match(_items[i])) return i;
            }

            return -1;
        }

19 View Source File : UnmanagedList.cs
License : MIT License
Project Creator : b-editor

public T? FindLast(Predicate<T> match)
        {
            if (match is null) throw new ArgumentNullException(nameof(match));

            for (var i = _size - 1; i >= 0; i--)
            {
                if (match(_items[i]))
                {
                    return _items[i];
                }
            }

            return default;
        }

19 View Source File : UnmanagedList.cs
License : MIT License
Project Creator : b-editor

public int FindLastIndex(int startIndex, int count, Predicate<T> match)
        {
            if (match is null) throw new ArgumentNullException(nameof(match));

            if (_size == 0 && startIndex != -1)
            {
                throw new ArgumentOutOfRangeException(nameof(startIndex));
            }
            else if ((uint)startIndex >= (uint)_size)
            {
                throw new ArgumentOutOfRangeException(nameof(startIndex));
            }

            if (count < 0 || startIndex - count + 1 < 0) throw new ArgumentOutOfRangeException(nameof(count));

            var endIndex = startIndex - count;
            for (var i = startIndex; i > endIndex; i--)
            {
                if (match(_items[i]))
                {
                    return i;
                }
            }

            return -1;
        }

19 View Source File : UnmanagedList.cs
License : MIT License
Project Creator : b-editor

public bool TrueForAll(Predicate<T> match)
        {
            if (match is null) throw new ArgumentNullException(nameof(match));
            for (var i = 0; i < _size; i++)
            {
                if (!match(_items[i]))
                {
                    return false;
                }
            }

            return true;
        }

19 View Source File : IListExt.cs
License : MIT License
Project Creator : baba-s

public static IList<T> FindAll<T>( this IList<T> self, Predicate<T> match )
		{
			var result = new List<T>();
			for ( int i = 0; i < self.Count; i++ )
			{
				if ( match( self[ i ] ) )
				{
					result.Add( self[ i ] );
				}
			}
			return result;
		}

19 View Source File : IListExt.cs
License : MIT License
Project Creator : baba-s

public static T Find<T>( this IList<T> self, Predicate<T> match )
		{
			for ( int i = 0; i < self.Count; i++ )
			{
				if ( match( self[ i ] ) )
				{
					return self[ i ];
				}
			}
			return default( T );
		}

19 View Source File : IListExt.cs
License : MIT License
Project Creator : baba-s

public static int FindIndex<T>( this IList<T> self, Predicate<T> match )
		{
			for ( int i = 0; i < self.Count; i++ )
			{
				if ( match( self[ i ] ) )
				{
					return i;
				}
			}
			return -1;
		}

19 View Source File : IListExt.cs
License : MIT License
Project Creator : baba-s

public static T FindLast<T>( this IList<T> self, Predicate<T> match )
		{
			for ( int i = self.Count - 1; 0 <= i; i-- )
			{
				if ( match( self[ i ] ) )
				{
					return self[ i ];
				}
			}
			return default( T );
		}

19 View Source File : IListExt.cs
License : MIT License
Project Creator : baba-s

public static int FindLastIndex<T>( this IList<T> self, Predicate<T> match )
		{
			for ( int i = self.Count - 1; 0 <= i; i-- )
			{
				if ( match( self[ i ] ) )
				{
					return i;
				}
			}
			return -1;
		}

19 View Source File : OrderedHashSet.cs
License : MIT License
Project Creator : Bannerlord-Coop-Team

public int RemoveWhere(Predicate<T> match)
        {
            if (match == null)
            {
                throw new ArgumentNullException(nameof(match));
            }

            int numRemoved = 0;
            for (int i = 0; i < m_lastIndex; i++)
            {
                if (m_slots[i].hashCode >= 0)
                {
                    // cache value in case delegate removes it
                    T value = m_slots[i].value;
                    if (match(value))
                    {
                        // check again that remove actually removed it 
                        if (Remove(value))
                        {
                            numRemoved++;
                        }
                    }
                }
            }

            return numRemoved;
        }

19 View Source File : RuleCommandScope.cs
License : MIT License
Project Creator : bartoszlenar

public void Validate(T model, IValidationContext context)
        {
            var shouldExecute = ExecutionCondition?.Invoke(model) ?? true;

            if (!shouldExecute)
            {
                return;
            }

            context.EnterPath(Path);

            if (!IsValid(model))
            {
                context.AddError(ErrorId);
            }

            context.LeavePath();
        }

19 View Source File : GridBase2D.cs
License : MIT License
Project Creator : bartofzo

public UnitWrapper Nearest(Vector2 position, float limit, Predicate<T> predicate, out float nearestDistSquared)
            {
                float limitSquared = limit * limit;
                UnitWrapper nearestWrapper = null;

                nearestDistSquared = float.PositiveInfinity;

                foreach (var wrapper in _unitWrappers)
                {
                    float d = wrapper.Shape.DistanceSquared(position);

                    if (d < nearestDistSquared && d < limitSquared && predicate(wrapper.Unit))
                    {
                        nearestDistSquared = d;
                        nearestWrapper = wrapper;
                    }
                }

                return nearestWrapper;
            }

19 View Source File : GridBase2D.cs
License : MIT License
Project Creator : bartofzo

public IEnumerable<UnitWrapper> Contact(IConvex2D shape, Predicate<T> predicate, int queryNumber)
            {
                foreach (var wrapper in _unitWrappers)
                {
                    // Make sure to check each unit only once. Certain shapes might span multiple cells.
                    if (!wrapper.Once(queryNumber))
                        continue;

                    if (!shape.NoContactCertainty(wrapper.Shape) &&
                        !wrapper.Shape.NoContactCertainty(shape) &&
                        predicate(wrapper.Unit))
                        yield return wrapper;
                }
            }

19 View Source File : CommandScope.cs
License : MIT License
Project Creator : bartoszlenar

public void Validate(T model, IValidationContext context)
        {
            var shouldExecute = ExecutionCondition?.Invoke(model) ?? true;

            if (!shouldExecute)
            {
                return;
            }

            context.EnterPath(Path);

            if (ErrorId.HasValue)
            {
                context.EnableErrorDetectionMode(ErrorMode, ErrorId.Value);
            }

            RunValidation(model, context);

            context.LeavePath();
        }

19 View Source File : RangeObservableCollection.cs
License : MIT License
Project Creator : beto-rodriguez

public int RemoveAll(int index, int count, Predicate<T> 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 is null)
                throw new ArgumentNullException(nameof(match));

            if (Count == 0)
                return 0;

            List<T>? cluster = null;
            var clusterIndex = -1;
            var removedCount = 0;

            using (BlockReentrancy())
            using (DeferEvents())
            {
                for (var i = 0; i < count; i++, index++)
                {
                    var item = Items[index];
                    if (match(item))
                    {
                        Items.RemoveAt(index);
                        removedCount++;

                        if (clusterIndex == index)
                        {
                            Debug.replacedert(cluster is not null);
                            cluster!.Add(item);
                        }
                        else
                        {
                            cluster = new List<T> { item };
                            clusterIndex = index;
                        }

                        index--;
                    }
                    else if (clusterIndex > -1)
                    {
                        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, cluster, clusterIndex));
                        clusterIndex = -1;
                        cluster = null;
                    }
                }

                if (clusterIndex > -1)
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, cluster, clusterIndex));
            }

            if (removedCount > 0)
                OnEssentialPropertiesChanged();

            return removedCount;
        }

See More Examples