Click or drag to resize

GenericExtensions Class

Utility class, containing extension methods for classes in the generic namespace
Inheritance Hierarchy
SystemObject
  DHI.Mike1D.GenericGenericExtensions

Namespace:  DHI.Mike1D.Generic
Assembly:  DHI.Mike1D.Generic (in DHI.Mike1D.Generic.dll) Version: 16.0.0.0 (11.1.1.1111)
Syntax
C#
public static class GenericExtensions

The GenericExtensions type exposes the following members.

Methods
  NameDescription
Public methodStatic memberCode exampleBinarySearchT(IListT, FuncT, Int32)
Searches the entire sorted IListT for an element using the provided comparer and returns the zero-based index of the element.

This differs from the "ordinary" binary search in allowing a comparer delegate that defines whether an item is found (returning 0), whether the item in the list is before (<0) or after (>0) that knows how to compare a class with its key. Example, if the list contains classes of type T having an id number and the class is sorted on that id, then the keySelector returns the id number for that class.

Examples
If having a list of doubles, to find 4.5 in the list, use:
int index = list.BinarySearch(d => d.CompareTo(4.5))
Public methodStatic memberBinarySearchT(IListT, T)
Searches the entire sorted IListT for an element and returns the zero-based index of the element.

If the key is not found, a negative number is returned, which can be intepreted as the bitwise complement of the interval of indices that the key is in between, i.e.

list[interval-1] < key < list[interval]

Public methodStatic memberBinarySearchT(IListT, T, IComparerT)
Searches the entire sorted IListT for an element using the provided comparer and returns the zero-based index of the element.

If the key is not found, a negative number is returned, which can be intepreted as the bitwise complement of the interval of indices that the key is in between, i.e.

list[interval-1] < key < list[interval]

Public methodStatic memberBinarySearchT, TKey(IListT, FuncT, TKey, TKey)
Searches the entire sorted IListT for an element and returns the zero-based index of the element.

If the key is not found, a negative number is returned, which can be intepreted as the bitwise complement of the interval of indices that the key is in between, i.e.

list[interval-1] < key < list[interval]

This differs from the "ordinary" binary search in allowing a keySelectorcomparer that knows how to compare a class with its key. Example, if the list contains classes of type T having an id number and the class is sorted on that id, then the keySelector returns the id number for that class.

Public methodStatic memberBinarySearchT, TKey(IListT, FuncT, TKey, TKey, IComparerTKey)
Searches the entire sorted IListT for an element using the provided comparer and returns the zero-based index of the element.

If the key is not found, a negative number is returned, which can be intepreted as the bitwise complement of the interval of indices that the key is in between, i.e.

list[interval-1] < key < list[interval]

This differs from the "ordinary" binary search in allowing a keySelectorcomparer that knows how to compare a class with its key. Example, if the list contains classes of type T having an id number and the class is sorted on that id, then the keySelector returns the id number for that class.

Public methodStatic memberChainageAsDiagnosticsValue
Get chainage as DiagnosticsValue (includes unit)
Public methodStatic memberCopyTo
Convert a double array to a float array.
Public methodStatic memberCopyToFloatArray
Convert a double array to a float array.
Public methodStatic memberError
Add an error to the diagnostics item.
Public methodStatic memberExceptionToError
Add an error DiagnosticItem, and throw an exception
Public methodStatic memberExceptionToString
Create string from exception, including inner exceptions
Public methodStatic memberFirstInMonth
Returns the first day in a month, at time 00:00:00.
Public methodStatic memberGetValueT(NetworkDataT, ILocation)
Get a value from the networkData at the given location. If no value is found at location, the global value is used. If no global value is defined, an exception is thrown.
Public methodStatic memberGetValueT(NetworkDataT, ILocation, T)
Get a value from the networkData at the given location. If no value is found at location, the global value is used. If no global value is defined, the default value is returned.
Public methodStatic memberIndexOf(IListIQuantity, IQuantity, Boolean)
Search the list of quantities for the given quantity
Public methodStatic memberIndexOf(IListIQuantity, IQuantity, IListString)
Search the list of quantities for the given quantity, allow the description to be also one listed in descriptions.
Public methodStatic memberCode exampleLargestMultipleOf
Make span the largest multiple of the spanRef that is smaller than span
Public methodStatic memberMin
Returns the smallest of t1 and t2
Public methodStatic memberMultiply
Multiply the timespane 'dt' by a double. If the double is larger than 1e6, then 1e6 is used in order to prevent overflow
Public methodStatic memberRuntimeError
Add an error DiagnosticItem, and throw an exception
Public methodStatic memberSet
Set a value to the table
Public methodStatic memberSort(IXYTable)
Sort table by x-value, using a quick-sort algorithm
Public methodStatic memberSortT(IListT)
Sorts the elements in the entire List{T} using the default comparer.

A quick sort algorithm is used. Quick sort is a un-stable sort algorithm i.e. if two elements are equal their order may not be preserved.

If the provided IList is either an array or a list, the build in sorting method is used (also quick sort).

Public methodStatic memberSortT(IListT, IComparerT)
Sorts the elements in the entire List{T} using the provided comparer.

A quick sort algorithm is used. Quick sort is a un-stable sort algorithm i.e. if two elements are equal their order may not be preserved.

If the provided IList is either an array or a list, the build in sorting method is used (also quick sort).

Public methodStatic memberSortStable(IXYTable)
Sort table by x-value, using a stable sort
Public methodStatic memberSortStableT(IListT)
Public methodStatic memberSortStableT(IListT, IComparerT)
Sorts the elements in the entire List{T} using the provided comparer.

A merge sort algorithm is used. merge sort is a stable sort algorithm i.e. if two elements are equal their order are preserved.

Public methodStatic memberSortStableT(IListT, ComparisonT)
Sorts the elements in the entire List{T} using the provided comparer.

A merge sort algorithm is used. merge sort is a stable sort algorithm i.e. if two elements are equal their order are preserved.

Public methodStatic memberSwapT
Swapping two elements.
Public methodStatic memberWarning
Add a warning message
Top
See Also