Class Utilities
Provides a set of static utility methods for collection operations, and general-purpose helpers.
public static class Utilities
- Inheritance
-
objectUtilities
Methods
Compare<TKey, TValue>(SortedList<TKey, TValue>, SortedList<TKey, TValue>)
Compares two collection, element by elements.
public static bool Compare<TKey, TValue>(SortedList<TKey, TValue> first, SortedList<TKey, TValue> second)
Parameters
firstSortedList<TKey, TValue>The collection to compare from.
secondSortedList<TKey, TValue>The colllection to compare to.
Returns
- bool
True if lists are identical (but not necessarily in the same order). False otherwise.
Type Parameters
TKeyTValue
Remarks
Concrete SortedList is favored over interface to avoid enumerator object allocation.
Compare<TKey, TValue>(IDictionary<TKey, TValue>, IDictionary<TKey, TValue>)
Compares two collection, element by elements.
public static bool Compare<TKey, TValue>(IDictionary<TKey, TValue> first, IDictionary<TKey, TValue> second)
Parameters
firstIDictionary<TKey, TValue>The collection to compare from.
secondIDictionary<TKey, TValue>The colllection to compare to.
Returns
- bool
True if lists are identical (but no necessarely of the same time). False otherwise.
Type Parameters
TKeyTValue
ConvertRawToTimestamp(long)
public static TimeSpan ConvertRawToTimestamp(long delta)
Parameters
deltalongThe delta.
Returns
Dispose<T>(ref T?)
Disposes an IDisposable object if not null, and sets it to null.
public static void Dispose<T>(ref T? disposable) where T : class, IDisposable
Parameters
disposableTThe disposable object to dispose.
Type Parameters
T
GetHashCode(IDictionary)
Computes a hashcode for a dictionary.
public static int GetHashCode(IDictionary dict)
Parameters
dictIDictionary
Returns
- int
Hashcode for the list.
GetHashCode(IEnumerable)
Computes a hashcode for an enumeration
public static int GetHashCode(IEnumerable it)
Parameters
itIEnumerableAn enumerator.
Returns
- int
Hashcode for the list.
GetHashCode(IEnumerator)
Computes a hashcode for an enumeration
public static int GetHashCode(IEnumerator it)
Parameters
itIEnumeratorAn enumerator.
Returns
- int
Hashcode for the list.
IterateTree<T>(T, Func<T, IEnumerable<T>>)
Linq assisted full tree iteration and collection in a single line. Warning, could be slow.
public static IEnumerable<T> IterateTree<T>(T root, Func<T, IEnumerable<T>> childrenF)
Parameters
rootTThe root item
childrenFFunc<T, IEnumerable<T>>The function to retrieve a child
Returns
- IEnumerable<T>
Type Parameters
TThe type to iterate.
ReadStream(Stream)
Read stream to a byte[] buffer
[Obsolete("Allocates. Read into the destination.")]
public static byte[] ReadStream(Stream stream)
Parameters
streamStreaminput stream
Returns
- byte[]
a byte[] buffer