Show / Hide Table of Contents

Class CommonUtils

Various utility functions

Inheritance
object
CommonUtils
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Cognite.Extractor.Common
Assembly: Cognite.Common.dll
Syntax
public static class CommonUtils

Methods

| Edit this page View Source

DistinctBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, IEqualityComparer<TKey>?)

Returns elements of the source enumerable, where all elments have distinct results of selector. If there are duplicates, only the first occurence in the input enumerable will be used.

Declaration
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> selector, IEqualityComparer<TKey>? comparer = null)
Parameters
Type Name Description
IEnumerable<TSource> source

Input enumerable

Func<TSource, TKey> selector

Function to generate keys

IEqualityComparer<TKey> comparer

Optional element comparer

Returns
Type Description
IEnumerable<TSource>

Entries of the source enumerable, where all elements have distinct results of selector

Type Parameters
Name Description
TSource
TKey
| Edit this page View Source

GetValue<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue)

Try to get the value associated with the provided key. If it is not found, returns defaultValue

Declaration
public static TValue GetValue<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, TValue defaultValue)
Parameters
Type Name Description
IDictionary<TKey, TValue> dict

This dictionary

TKey key

Key to search

TValue defaultValue

Default value to return

Returns
Type Description
TValue

Value or default

Type Parameters
Name Description
TKey
TValue
| Edit this page View Source

GroupByTimeGranularity<T>(IEnumerable<T>, TimeSpan, Func<T, DateTime>, int)

Group input by some granularity, so that the result is a list of lists where each inner list contains only elements within granularity time of each other.

Declaration
public static IEnumerable<IEnumerable<T>> GroupByTimeGranularity<T>(this IEnumerable<T> items, TimeSpan granularity, Func<T, DateTime> tsSelector, int maxLength)
Parameters
Type Name Description
IEnumerable<T> items

Input enumerable

TimeSpan granularity

Granularity to chunk by

Func<T, DateTime> tsSelector

Function to get timestamp for each element

int maxLength

Maximum number of elements in each inner list

Returns
Type Description
IEnumerable<IEnumerable<T>>

A list of lists where each inner list contains only elements within granularity time of each other.

Type Parameters
Name Description
T

Input element type

| Edit this page View Source

MinMax<T, R>(IEnumerable<T>, Func<T, R>)

Get the minimum and maximum value in a list, using selector to get the value for each item. Throws an exception if no elements are present.

Declaration
public static (R Min, R Max) MinMax<T, R>(this IEnumerable<T> items, Func<T, R> selector) where R : IComparable
Parameters
Type Name Description
IEnumerable<T> items

Input enumerable

Func<T, R> selector

Function to get value for each element

Returns
Type Description
(R Min, R Max)

A tuple (Min, Max)

Type Parameters
Name Description
T

Input element type

R

Comparable element

| Edit this page View Source

TrimToNull(string?)

Trim this string object to null.

Declaration
public static string? TrimToNull(this string? @this)
Parameters
Type Name Description
string this
Returns
Type Description
string

A string without leading or trailing whitespace, or null.

| Edit this page View Source

WaitAsync(WaitHandle, TimeSpan, CancellationToken)

Convenient method to efficiently wait for a wait handle and cancellation token with timeout asynchronously.

Declaration
public static Task<bool> WaitAsync(WaitHandle handle, TimeSpan timeout, CancellationToken token)
Parameters
Type Name Description
WaitHandle handle

WaitHandle to wait for

TimeSpan timeout

Wait timeout

CancellationToken token

Cancellation token

Returns
Type Description
Task<bool>

True if wait handle or cancellation token was triggered, false otherwise

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX