GenericExtensions Class

Utility class, containing extension methods for classes in the generic namespace

Definition

Namespace: DHI.Mike1D.Generic
Assembly: DHI.Mike1D.Generic (in DHI.Mike1D.Generic.dll) Version: 24.0.0.0 (11.1.1.1111)
C#
public static class GenericExtensions
Inheritance
Object    GenericExtensions

Methods

AddToListT, TKey Add value to list associated with key. If no list exist for value, list is added
BinarySearchT(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]

BinarySearchT(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.

Example

If having a list of doubles, to find 4.5 in the list, use: int index = list.BinarySearch(d => d.CompareTo(4.5))
BinarySearchT(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]

BinarySearchT, 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.

BinarySearchT, TKey(ListT, 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.

BinarySearchT, 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.

BinarySearchT, TKey(ListT, 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.

BinarySearchROT, TKey(IReadOnlyListT, FuncT, TKey, TKey) Searches the entire sorted IReadOnlyListT 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.

BinarySearchROT, TKey(IReadOnlyListT, FuncT, TKey, TKey, IComparerTKey) Searches the entire sorted IReadOnlyListT 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.

ChainageAsDiagnosticsValue Get chainage as DiagnosticsValue (includes unit)
ChainageEquals(ILocation, Double) Returns true if the chainage equals, withing LOCATION_EQUAL_TOLERANCE
ChainageEquals(ILocation, Double, Double) Returns true if the chainage equals, withing tolerance
ChainageIsAfter(ILocation, Double) Returns true if the chainage is after, and more than LOCATION_EQUAL_TOLERANCE after

This is consistent with the ChainageEquals, so that any chainage will only return true for one of the ChainageIsBefore, ChainageEquals, ChainageIsAfter

ChainageIsAfter(ILocation, Double, Double) Returns true if the chainage is after, and more than tolerance after

This is consistent with the ChainageEquals, so that any chainage will only return true for one of the ChainageIsBefore, ChainageEquals, ChainageIsAfter

ChainageIsBefore(ILocation, Double) Returns true if the chainage is before, and more than LOCATION_EQUAL_TOLERANCE before

This is consistent with the ChainageEquals, so that any chainage will only return true for one of the ChainageIsBefore, ChainageEquals, ChainageIsAfter

ChainageIsBefore(ILocation, Double, Double) Returns true if the chainage is before, and more than tolerance before

This is consistent with the ChainageEquals, so that any chainage will only return true for one of the ChainageIsBefore, ChainageEquals, ChainageIsAfter

CopyTo Convert a double array to a float array.
CopyToFloatArray Convert a double array to a float array.
CreateAndAddChild Create a child watch and add it to the parent
Error Add an error to the diagnostics item.
ExceptionToError Add an error DiagnosticItem, and throw an exception
ExceptionToString Create string from exception, including inner exceptions
FindIndexT(IListT, PredicateT)Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the list.
FindIndexT(IListT, Int32, PredicateT)Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the ListT that extends from the specified index to the last element.
FirstInMonth Returns the first day in a month, at time 00:00:00.
GetLowestPointIndex Get the index of the lowest point (smallest point.Z) in the list of points.
GetValueT(IDictionaryString, T, String) Get value, based on key. If no data exist for value, null is returned
GetValueT(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.
GetValueT(NetworkDataT, String) Get a value from the networkData at the given nodeId. If no value is found at location, the global value is used. If no global value is defined, an exception is thrown.
GetValueT(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.
GetValueT(NetworkDataT, String, T) Get a value from the networkData at the given nodeId. If no value is found at location, the global value is used. If no global value is defined, the default value is returned.
GetValueOrDefaultAddT, TKey Get value, based on key. If no data exist for value, default object is added and returned
GetValuesT(IVectorGetterT) Get values from engineDataReach, copying data to a new array.
GetValuesT(IVectorGetterT, T) Get values from engineDataReach, copying data to data.
GetValuesT(IVectorFractionGetterT, T, Double) Get values from engineDataReach, copying data to data.
IndexOf(IListIQuantity, IQuantity, Boolean) Search the list of quantities for the given quantity
IndexOf(IListIQuantity, IQuantity, IListString) Search the list of quantities for the given quantity, allow the description to be also one listed in descriptions.
IsOneOf Returns true if enumeration is one of the listed ones.
IsSediment True if component type is a sediment type
LargestMultipleOf Make span the largest multiple of the spanRef that is smaller than span
Min Returns the smallest of t1 and t2
Multiply Multiply the timespane 'dt' by a double. If the double is larger than 1e6, then 1e6 is used in order to prevent overflow
OverLap(ILocationSpan, ILocationSpan) Calculate overlap of location span and another locationSpan. If the result is positive, the value is the actual overlap. If the result is negative, there is no overlap, and the value is the negative distance between the two spans.
OverLap(ILocationSpan, Double, Double) Calculate overlap of location span and the chainages of another locationSpan. If the result is positive, the value is the actual overlap. If the result is negative, there is no overlap, and the value is the negative distance between the two spans.
Quantity(PredefinedQuantity) Get quantity for PredefinedQuantity, predef
Quantity(PredefinedQuantity, String) Get quantity for PredefinedQuantity, predef, adding description to Description.
RuntimeError Add an error DiagnosticItem, and throw an exception
Set Set a value to the table
SetupParameterT Get setup parameter, based on key. If value is not of type {T}, false is returned.

It is assumed that the dictionary had a key called SetupParametersStr with a value implementing IEnumerable<KeyValuePair<string, object>>, which then the key is looking up into.

This can be used with "SetupParameters" in the Options.

Sort(IXYTable) Sort table by x-value, using a quick-sort algorithm
SortT(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).

SortT(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).

SortStable(IXYTable) Sort table by x-value, using a stable sort
SortStableT(IListT) Sorts the elements in the entire List{T} using the default 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.

SortStableT(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.

SortStableT(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.

SwapT Swapping two elements.
TryGetEnumValueT Get enum value, based on key, assuming value is a string representation of the enum value. If no data exist for value, or it could not be parsed as an enum value, returns the defaultValue
TryGetSetupParameterT Get Setup Parameter, based on key. If value is not of type {T}, false is returned.

It is assumed that the dictionary had a key called SetupParametersStr with a value implementing IEnumerable<KeyValuePair<string, object>>, which then the key is looking up into.

This can be used with "SetupParameters" in the Options.

TryGetValueT(IDictionaryString, Object, String, T) Get additional data, based on key. If no data exist for value, return the defaultValue
TryGetValueT(IDictionaryString, Object, String, T) Get additional data, based on key. If value is not of type {T}, false is returned.
Warning Add a warning message

See Also