CollectionExtensionMethods

public static class CollectionExtensionMethods
Provides extension methods for enumerable collections.

Methods

AddFlexible

#Example
Add a (possibly) hierarchical layer.
public static int AddFlexible(
layers,
Layer set to search and modify.
name
Full path or name of layer.
)
Index of layer or -1.

AddFlexible

#Example
Add a (possibly) hierarchical layer.
public static int AddFlexible(
layers,
Layer set to search and modify.
name
Full path or name of layer.
)
Index of layer or -1.

CommonValue<T>

#Example
Either return the value that all elements in the collection have or null.
public static bool CommonValue<T>(
this IEnumerable<T>
collection,
Collection to traverse.
Func<T, T, bool>
comparison,
Comparer.
out T
commonValue
Common value, if found.
)
Value shared amongst all entries or null.

CommonValue<T>

#Example
Either return the value that all elements in the collection have or null. This method uses ReferenceEquals to test for equality, you will probably want to use the overload which takes a specific comparison delegate.
public static bool CommonValue<T>(
this IEnumerable<T>
collection,
Collection to traverse.
out T
commonValue
Common value, if found.
)
True if there was a common value.

CommonValue<TValue, TType>

#Example
Extract a specific struct value all elements in a collection share, or return null. All values are compared using default comparison.
public static TValue? CommonValue<TValue, TType>(
this IEnumerable<TType>
collection,
Collection to iterate over.
Func<TType, TValue>
accessor
Method for getting at values in collection items.
)
The value all elements have in common, or null.

FindFlexible

#Example
Search for a layer first by full path and then by name.
public static int FindFlexible(
layers,
Layer set to search.
name
Full path or name of layer.
)
Index of layer or -1.

FindFlexible

#Example
Search for a layer first by full path and then by name.
public static int FindFlexible(
layers,
Layer set to search.
name
Full path or name of layer.
)
Index of layer or -1.

Toggle<T>

#Example
Remove an element from a hashset if it exists, or add it if it doesn't.
public static void Toggle<T>(
this HashSet<T>
hashset,
T
element
)

ToInstanceIdSet

#Example
Collect the instance IDs of all objects and subobjects in a collection into a hash set.
public static HashSet<Guid> ToInstanceIdSet()

TrueForSome<T>

#Example
Test whether a predicate holds for any of the values in a collection.
public static bool TrueForSome<T>(
this IEnumerable<T>
collection,
Func<T, bool>
predicate
)