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
19
Source : Utility.Assert.cs
with MIT License
from DonnYep
with MIT License
from DonnYep
public static void Predicate<T>(T arg, Predicate<T> handler, Action<T> callBack)
{
if (handler == null)
return;
if (handler.Invoke(arg))
callBack?.Invoke(arg);
}
19
Source : ArrayExtensions.cs
with MIT License
from dotnet-toolbelt
with MIT License
from dotnet-toolbelt
public static T[] RemoveAll<T>(this T[] source, Predicate<T> predicate)
{
var result = new T[source.Length - source.Count(s => predicate(s))];
var i = 0;
foreach (var item in source.Where(item => !predicate(item)))
{
result[i] = item;
i++;
}
return result;
}
19
Source : List.cs
with MIT License
from dotnetGame
with MIT License
from dotnetGame
public int RemoveAll(Predicate<T> match)
{
if (match == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
int freeIndex = 0; // the first free slot in items array
// Find the first item which needs to be removed.
while (freeIndex < _size && !match(_items[freeIndex])) freeIndex++;
if (freeIndex >= _size) return 0;
int current = freeIndex + 1;
while (current < _size)
{
// Find the first item which needs to be kept.
while (current < _size && match(_items[current])) current++;
if (current < _size)
{
// copy item to the free slot.
_items[freeIndex++] = _items[current++];
}
}
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
Array.Clear(_items, freeIndex, _size - freeIndex); // Clear the elements so that the gc can reclaim the references.
}
int result = _size - freeIndex;
_size = freeIndex;
_version++;
return result;
}
19
Source : List.cs
with MIT License
from dotnetGame
with MIT License
from dotnetGame
public T Find(Predicate<T> match)
{
if (match == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
for (int i = 0; i < _size; i++)
{
if (match(_items[i]))
{
return _items[i];
}
}
return default;
}
19
Source : List.cs
with MIT License
from dotnetGame
with MIT License
from dotnetGame
public List<T> FindAll(Predicate<T> match)
{
if (match == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
List<T> list = new List<T>();
for (int i = 0; i < _size; i++)
{
if (match(_items[i]))
{
list.Add(_items[i]);
}
}
return list;
}
19
Source : List.cs
with MIT License
from dotnetGame
with MIT License
from dotnetGame
public int FindIndex(int startIndex, int count, Predicate<T> match)
{
if ((uint)startIndex > (uint)_size)
{
ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
}
if (count < 0 || startIndex > _size - count)
{
ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
}
if (match == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
int endIndex = startIndex + count;
for (int i = startIndex; i < endIndex; i++)
{
if (match(_items[i])) return i;
}
return -1;
}
19
Source : List.cs
with MIT License
from dotnetGame
with MIT License
from dotnetGame
public bool TrueForAll(Predicate<T> match)
{
if (match == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
for (int i = 0; i < _size; i++)
{
if (!match(_items[i]))
{
return false;
}
}
return true;
}
19
Source : List.cs
with MIT License
from dotnetGame
with MIT License
from dotnetGame
public T FindLast(Predicate<T> match)
{
if (match == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
for (int i = _size - 1; i >= 0; i--)
{
if (match(_items[i]))
{
return _items[i];
}
}
return default;
}
19
Source : List.cs
with MIT License
from dotnetGame
with MIT License
from dotnetGame
public int FindLastIndex(int startIndex, int count, Predicate<T> match)
{
if (match == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
if (_size == 0)
{
// Special case for 0 length List
if (startIndex != -1)
{
ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
}
}
else
{
// Make sure we're not out of range
if ((uint)startIndex >= (uint)_size)
{
ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
}
}
// 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
if (count < 0 || startIndex - count + 1 < 0)
{
ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
}
int endIndex = startIndex - count;
for (int i = startIndex; i > endIndex; i--)
{
if (match(_items[i]))
{
return i;
}
}
return -1;
}
19
Source : MDList.cs
with MIT License
from DoubleDeez
with MIT License
from DoubleDeez
public int RemoveAll(Predicate<T> match)
{
List<KeyValuePair<T, IMDDataConverter>> items = RealList.FindAll((KeyValuePair<T, IMDDataConverter> x) => match.Invoke(x.Key));
items.ForEach(item => Remove(item.Key));
return items.Count;
}
19
Source : SuperList.cs
with Apache License 2.0
from eaglet2006
with Apache License 2.0
from eaglet2006
public SuperList<T> FindAll(Predicate<T> match)
{
if (match == null)
{
throw new ArgumentNullException();
}
SuperList<T> list = new SuperList<T>();
for (int i = 0; i < _size; i++)
{
if (match(_items[i]))
{
list.Add(_items[i]);
}
}
return list;
}
19
Source : SuperList.cs
with Apache License 2.0
from eaglet2006
with Apache License 2.0
from eaglet2006
public int FindIndex(int startIndex, int count, Predicate<T> match)
{
if ((uint)startIndex > (uint)_size)
{
throw new ArgumentOutOfRangeException();
}
if (count < 0 || startIndex > _size - count)
{
throw new ArgumentOutOfRangeException();
}
if (match == null)
{
throw new ArgumentNullException();
}
int endIndex = startIndex + count;
for (int i = startIndex; i < endIndex; i++)
{
if (match(_items[i])) return i;
}
return -1;
}
19
Source : SuperList.cs
with Apache License 2.0
from eaglet2006
with Apache License 2.0
from eaglet2006
public T FindLast(Predicate<T> match)
{
if (match == null)
{
throw new ArgumentNullException();
}
for (int i = _size - 1; i >= 0; i--)
{
if (match(_items[i]))
{
return _items[i];
}
}
return default(T);
}
19
Source : SuperList.cs
with Apache License 2.0
from eaglet2006
with Apache License 2.0
from eaglet2006
public T Find(Predicate<T> match)
{
if (match == null)
{
throw new ArgumentNullException();
}
for (int i = 0; i < _size; i++)
{
if (match(_items[i]))
{
return _items[i];
}
}
return default(T);
}
19
Source : SuperList.cs
with Apache License 2.0
from eaglet2006
with Apache License 2.0
from eaglet2006
public int FindLastIndex(int startIndex, int count, Predicate<T> match)
{
if (match == null)
{
throw new ArgumentNullException();
}
if (_size == 0)
{
// Special case for 0 length SuperList
if (startIndex != -1)
{
throw new ArgumentOutOfRangeException();
}
}
else
{
// Make sure we're not out of range
if ((uint)startIndex >= (uint)_size)
{
throw new ArgumentOutOfRangeException();
}
}
// 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
if (count < 0 || startIndex - count + 1 < 0)
{
throw new ArgumentOutOfRangeException();
}
int endIndex = startIndex - count;
for (int i = startIndex; i > endIndex; i--)
{
if (match(_items[i]))
{
return i;
}
}
return -1;
}
19
Source : SuperList.cs
with Apache License 2.0
from eaglet2006
with Apache License 2.0
from eaglet2006
public int RemoveAll(Predicate<T> match)
{
if (match == null)
{
throw new ArgumentNullException();
}
int freeIndex = 0; // the first free slot in items array
// Find the first item which needs to be removed.
while (freeIndex < _size && !match(_items[freeIndex])) freeIndex++;
if (freeIndex >= _size) return 0;
int current = freeIndex + 1;
while (current < _size)
{
// Find the first item which needs to be kept.
while (current < _size && match(_items[current])) current++;
if (current < _size)
{
// copy item to the free slot.
_items[freeIndex++] = _items[current++];
}
}
Array.Clear(_items, freeIndex, _size - freeIndex);
int result = _size - freeIndex;
_size = freeIndex;
_version++;
return result;
}
19
Source : SuperList.cs
with Apache License 2.0
from eaglet2006
with Apache License 2.0
from eaglet2006
public bool TrueForAll(Predicate<T> match)
{
if (match == null)
{
throw new ArgumentNullException();
}
for (int i = 0; i < _size; i++)
{
if (!match(_items[i]))
{
return false;
}
}
return true;
}
19
Source : DataTableManager.DataTable.cs
with MIT License
from EllanJiang
with MIT License
from EllanJiang
public bool HasDataRow(Predicate<T> condition)
{
if (condition == null)
{
throw new GameFrameworkException("Condition is invalid.");
}
foreach (KeyValuePair<int, T> dataRow in m_DataSet)
{
if (condition(dataRow.Value))
{
return true;
}
}
return false;
}
19
Source : DataTableManager.DataTable.cs
with MIT License
from EllanJiang
with MIT License
from EllanJiang
public T GetDataRow(Predicate<T> condition)
{
if (condition == null)
{
throw new GameFrameworkException("Condition is invalid.");
}
foreach (KeyValuePair<int, T> dataRow in m_DataSet)
{
if (condition(dataRow.Value))
{
return dataRow.Value;
}
}
return null;
}
19
Source : DataTableManager.DataTable.cs
with MIT License
from EllanJiang
with MIT License
from EllanJiang
public T[] GetDataRows(Predicate<T> condition)
{
if (condition == null)
{
throw new GameFrameworkException("Condition is invalid.");
}
List<T> results = new List<T>();
foreach (KeyValuePair<int, T> dataRow in m_DataSet)
{
if (condition(dataRow.Value))
{
results.Add(dataRow.Value);
}
}
return results.ToArray();
}
19
Source : DataTableManager.DataTable.cs
with MIT License
from EllanJiang
with MIT License
from EllanJiang
public void GetDataRows(Predicate<T> condition, List<T> results)
{
if (condition == null)
{
throw new GameFrameworkException("Condition is invalid.");
}
if (results == null)
{
throw new GameFrameworkException("Results is invalid.");
}
results.Clear();
foreach (KeyValuePair<int, T> dataRow in m_DataSet)
{
if (condition(dataRow.Value))
{
results.Add(dataRow.Value);
}
}
}
19
Source : DataTableManager.DataTable.cs
with MIT License
from EllanJiang
with MIT License
from EllanJiang
public T[] GetDataRows(Predicate<T> condition, Comparison<T> comparison)
{
if (condition == null)
{
throw new GameFrameworkException("Condition is invalid.");
}
if (comparison == null)
{
throw new GameFrameworkException("Comparison is invalid.");
}
List<T> results = new List<T>();
foreach (KeyValuePair<int, T> dataRow in m_DataSet)
{
if (condition(dataRow.Value))
{
results.Add(dataRow.Value);
}
}
results.Sort(comparison);
return results.ToArray();
}
19
Source : DataTableManager.DataTable.cs
with MIT License
from EllanJiang
with MIT License
from EllanJiang
public void GetDataRows(Predicate<T> condition, Comparison<T> comparison, List<T> results)
{
if (condition == null)
{
throw new GameFrameworkException("Condition is invalid.");
}
if (comparison == null)
{
throw new GameFrameworkException("Comparison is invalid.");
}
if (results == null)
{
throw new GameFrameworkException("Results is invalid.");
}
results.Clear();
foreach (KeyValuePair<int, T> dataRow in m_DataSet)
{
if (condition(dataRow.Value))
{
results.Add(dataRow.Value);
}
}
results.Sort(comparison);
}
19
Source : Context.cs
with MIT License
from Elringus
with MIT License
from Elringus
public static List<T> ResolveAll<T> (Predicate<T> predicate = null, bool strictType = true, bool replacedertResult = false) where T : clreplaced
{
var resolvingType = typeof(T);
if (resolvingType.IsInterface || resolvingType.IsAbstract)
strictType = false;
var refsOfType = GetReferencesOfType(resolvingType, strictType);
if (refsOfType == null || refsOfType.Count == 0)
{
if (replacedertResult)
Debug.LogError($"Failed to resolve objects of type '{resolvingType.Name}'");
return new List<T>();
}
return refsOfType
.Where(r => IsWeakRefValid(r) && (predicate == null || predicate(r.Target as T)))
.Select(r => r.Target)
.Cast<T>()
.ToList();
}
19
Source : LinqUtils.cs
with MIT License
from Elringus
with MIT License
from Elringus
public static int IndexOf<T> (this IList<T> list, Predicate<T> predicate)
{
var i = 0;
foreach (T item in list)
{
if (predicate(item)) return i;
i++;
}
return -1;
}
19
Source : LinqUtils.cs
with MIT License
from Elringus
with MIT License
from Elringus
public static int IndexOf<T> (this IReadOnlyList<T> list, Predicate<T> predicate)
{
var i = 0;
foreach (T item in list)
{
if (predicate(item)) return i;
i++;
}
return -1;
}
19
Source : LinqUtils.cs
with MIT License
from Elringus
with MIT License
from Elringus
public static int RemoveAll<T> (this LinkedList<T> list, Predicate<T> match)
{
if (list == null) throw new ArgumentNullException(nameof(list));
if (match == null) throw new ArgumentNullException(nameof(match));
var count = 0;
var node = list.First;
while (node != null)
{
var next = node.Next;
if (match(node.Value))
{
list.Remove(node);
count++;
}
node = next;
}
return count;
}
19
Source : Context.cs
with MIT License
from Elringus
with MIT License
from Elringus
public static T Resolve<T> (Predicate<T> predicate = null, bool strictType = true, bool replacedertResult = false) where T : clreplaced
{
T result = null;
var resolvingType = typeof(T);
if (resolvingType.IsInterface || resolvingType.IsAbstract)
strictType = false;
var refsOfType = GetReferencesOfType(resolvingType, strictType);
if (refsOfType != null && refsOfType.Count > 0)
{
var weakRef = refsOfType.FirstOrDefault(r => IsWeakRefValid(r) &&
(predicate == null || predicate(r.Target as T)));
if (weakRef != null) result = weakRef.Target as T;
}
if (result == null && ShouldAutoConstruct(resolvingType))
return ConstructAndRegister(resolvingType) as T;
if (result == null && replacedertResult)
Debug.LogError($"Failed to resolve object of type '{resolvingType.Name}'");
return result;
}
19
Source : ObjectUtils.cs
with MIT License
from Elringus
with MIT License
from Elringus
public static T FindObject<T> (Predicate<T> predicate = null) where T : clreplaced
{
return Object.FindObjectsOfType<Object>().FirstOrDefault(obj => obj is T &&
(predicate == null || predicate(obj as T))) as T;
}
19
Source : ObjectUtils.cs
with MIT License
from Elringus
with MIT License
from Elringus
public static List<T> FindObjects<T> (Predicate<T> predicate = null) where T : clreplaced
{
return Object.FindObjectsOfType<Object>().Where(obj => obj is T arg &&
(predicate == null || predicate(arg))).Cast<T>().ToList();
}
19
Source : RelayCommand.cs
with MIT License
from Eryux
with MIT License
from Eryux
public override bool CanExecute(object param)
{
return _canExecute == null ? true : _canExecute((T)param);
}
19
Source : Tree.cs
with MIT License
from EugenyN
with MIT License
from EugenyN
private T Find(T node, Predicate<T> match)
{
if (match(node))
return node;
foreach (var p in node.Nodes)
{
var fp = Find(p, match);
if (fp != null)
return fp;
}
return null;
}
19
Source : Tree.cs
with MIT License
from EugenyN
with MIT License
from EugenyN
public T Find(Predicate<T> match)
{
foreach (T p in Items)
if (match(p))
return p;
return null;
}
19
Source : Tree.cs
with MIT License
from EugenyN
with MIT License
from EugenyN
public List<T> FindAll(Predicate<T> match)
{
var result = new List<T>();
foreach (T p in Items)
if (match(p))
result.Add(p);
return result;
}
19
Source : FormExtensions.cs
with MIT License
from fahminlb33
with MIT License
from fahminlb33
public static int FindIndex<T>(this IList<T> list, Predicate<T> predicate)
{
int i = 0;
foreach (var item in list)
{
if (predicate(item)) return i;
i++;
}
return -1;
}
19
Source : Extensions.cs
with MIT License
from felixkmh
with MIT License
from felixkmh
public static bool TryFind<T>(this IEnumerable<T> items, Predicate<T> predicate, out T result)
{
foreach (var item in items)
{
if (predicate(item))
{
result = item;
return true;
}
}
result = default;
return false;
}
19
Source : SyncList.cs
with Apache License 2.0
from FieldWarning
with Apache License 2.0
from FieldWarning
public int FindIndex(Predicate<T> match)
{
for (int i = 0; i < objects.Count; ++i)
if (match(objects[i]))
return i;
return -1;
}
19
Source : SyncList.cs
with Apache License 2.0
from FieldWarning
with Apache License 2.0
from FieldWarning
public int RemoveAll(Predicate<T> match)
{
List<T> toRemove = new List<T>();
for (int i = 0; i < objects.Count; ++i)
if (match(objects[i]))
toRemove.Add(objects[i]);
foreach (T entry in toRemove)
{
Remove(entry);
}
return toRemove.Count;
}
19
Source : SyncList.cs
with Apache License 2.0
from FieldWarning
with Apache License 2.0
from FieldWarning
public List<T> FindAll(Predicate<T> match)
{
List<T> results = new List<T>();
for (int i = 0; i < objects.Count; ++i)
if (match(objects[i]))
results.Add(objects[i]);
return results;
}
19
Source : ExtendedObservableCollection.cs
with MIT License
from FlaUI
with MIT License
from FlaUI
public void RemoveAll(Predicate<T> match)
{
var removedItem = false;
for (var i = Items.Count - 1; i >= 0; i--)
{
if (match(Items[i]))
{
Items.RemoveAt(i);
removedItem = true;
}
}
if (removedItem)
{
OnPropertyChanged(new PropertyChangedEventArgs("Count"));
OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
}
19
Source : DisposableExtensions.cs
with MIT License
from framebunker
with MIT License
from framebunker
public static int RemoveAndDisposeAll<T> ([NotNull] this List<T> list, [NotNull] Predicate<T> test)
where T : IDisposable
{
return list.RemoveAll (item => item.DisposeIf (i => test (i)));
}
19
Source : DisposableExtensions.cs
with MIT License
from framebunker
with MIT License
from framebunker
public static int FastRemoveAndDisposeAll<T> ([NotNull] this List<T> list, [NotNull] Predicate<T> test)
where T : IDisposable
{
return list.FastRemoveAll (item => item.DisposeIf (i => test (i)));
}
19
Source : Pool.cs
with MIT License
from framebunker
with MIT License
from framebunker
[CanBeNull] public T Find ([CanBeNull] Predicate<T> match, bool pop = false, int offset = 0)
{
T instance = null;
offset %= m_Size;
for (int index = 0; index < m_Size; ++index)
{
instance = m_Pool[(index + offset) % m_Size];
if (instance != null && (match == null || match (instance)))
{
if (!pop)
{
break;
}
if (Interlocked.CompareExchange (ref m_Pool[index], null, instance) == instance)
{
Interlocked.Decrement (ref m_Stored);
break;
}
instance = null;
}
}
return instance;
}
19
Source : BlockingQueue.cs
with GNU General Public License v3.0
from FredTungsten
with GNU General Public License v3.0
from FredTungsten
public void Prioritize(Comparison<T> comparison, Predicate<T> condition)
{
lock (_queueLock)
{
var allEntries = _queue.ToList();
var toSort = allEntries.Where(e => condition(e)).ToList();
foreach (T entry in toSort)
{
allEntries.Remove(entry);
}
toSort.Sort(comparison);
allEntries.InsertRange(0, toSort);
_queue = new ConcurrentQueue<T>(allEntries);
}
}
19
Source : CollectionExtensions.cs
with MIT License
from funwaywang
with MIT License
from funwaywang
public static bool Exists<T>(this IEnumerable<T> list, Predicate<T> match)
{
if (list == null)
throw new ArgumentNullException();
foreach (T item in list)
{
if (match(item))
{
return true;
}
}
return false;
}
19
Source : CollectionExtensions.cs
with MIT License
from funwaywang
with MIT License
from funwaywang
public static T Find<T>(this IEnumerable<T> list, Predicate<T> match)
{
if (list == null)
throw new ArgumentNullException();
foreach (T item in list)
{
if (match(item))
{
return item;
}
}
return default(T);
}
19
Source : CollectionExtensions.cs
with MIT License
from funwaywang
with MIT License
from funwaywang
public static List<T> FindAll<T>(this IEnumerable<T> list, Predicate<T> match)
{
if (list == null)
throw new NullReferenceException();
List<T> result = new List<T>();
foreach (T item in list)
{
if (match(item))
result.Add(item);
}
return result;
}
19
Source : XList.cs
with MIT License
from funwaywang
with MIT License
from funwaywang
public int RemoveAll(Predicate<T> match)
{
if (match == null)
throw new ArgumentNullException();
int count = 0;
for (int i = Count - 1; i >= 0; i--)
{
if (match(this[i]))
{
this.RemoveAt(i);
count++;
}
}
return count;
}
19
Source : AbstractResolvedTypeParameter.cs
with MIT License
from fuse-open
with MIT License
from fuse-open
static Predicate<T> FilterNonStatic<T>(Predicate<T> filter) where T : clreplaced, IUnresolvedMember
{
if (filter == null)
return member => !member.IsStatic;
else
return member => !member.IsStatic && filter(member);
}
19
Source : EnumerableIndexing.cs
with MIT License
from fuse-open
with MIT License
from fuse-open
public static int IndexOfFirst<T>(this IEnumerable<T> items, Predicate<T> where)
{
var i = 0;
foreach (var item in items)
{
if (where(item))
return i;
i++;
}
return -1;
}
See More Examples