Table of Contents

Class Extensions

Namespace
CriusNyx.Util
Assembly
CriusNyxUtil.dll

Extensions for manipulating ordinary objects.

public static class Extensions
Inheritance
Extensions
Inherited Members

Methods

AndWith<T, U, V>((T, U), V)

Extend a tuple with an additional element.

public static (T, U, V) AndWith<T, U, V>(this (T, U) value, V other)

Parameters

value (T, U)
other V

Returns

(T, U, V)

Type Parameters

T
U
V

AndWith<T, U, V, W>((T, U, V), W)

Extend a tuple with an additional element.

public static (T, U, V, W) AndWith<T, U, V, W>(this (T, U, V) value, W other)

Parameters

value (T, U, V)
other W

Returns

(T, U, V, W)

Type Parameters

T
U
V
W

AsNotNull<T>(object, string?)

Convert value to T and assert that it's not null. Throws an exception otherwise. Lets you generate a null reference stack trace at the point of assignment rather then when dereferenced.

public static T AsNotNull<T>(this object value, string? fieldName = null)

Parameters

value object
fieldName string

Returns

T

Type Parameters

T

As<T>(object)

Cast the element to the specified type T or return the default T otherwise.

public static T? As<T>(this object value)

Parameters

value object

Returns

T

Type Parameters

T

Expand<T, U, V>((T, U), Func<U, (U, V)>)

Expand a tuple by using the expander function on the last element.

public static (T, U, V) Expand<T, U, V>(this (T, U) value, Func<U, (U, V)> expander)

Parameters

value (T, U)
expander Func<U, (U, V)>

Returns

(T, U, V)

Type Parameters

T
U
V

Expand<T, U, V, W>((T, U, V), Func<V, (V, W)>)

Expand a tuple by using the expander function on the last element.

public static (T, U, V, W) Expand<T, U, V, W>(this (T, U, V) value, Func<V, (V, W)> expander)

Parameters

value (T, U, V)
expander Func<V, (V, W)>

Returns

(T, U, V, W)

Type Parameters

T
U
V
W

NotNull<T>(T?, string?)

Assert that the object is not null, and throw an exception if it is. Lets you generate a null reference stack trace at the point of assignment rather then when dereferenced.

public static T NotNull<T>(this T? value, string? fieldName = null)

Parameters

value T
fieldName string

Returns

T

Type Parameters

T

Exceptions

NullReferenceException

OrDefaultWith<T>(T?, Func<T>)

Returns the value, or the result of the provided function if the value is null.

public static T OrDefaultWith<T>(this T? value, Func<T> defaultFunc)

Parameters

value T
defaultFunc Func<T>

Returns

T

Type Parameters

T

OrDefault<T>(T?, T)

Returns the value, or the provided default is value is null.

public static T OrDefault<T>(this T? value, T defaultValue)

Parameters

value T
defaultValue T

Returns

T

Type Parameters

T

Safe<T>(IList<T>, int)

Dereference an element from the list or return the default value for the type if the index is outside the list.

public static T? Safe<T>(this IList<T> list, int index)

Parameters

list IList<T>
index int

Returns

T

Type Parameters

T

Safe<T>(T[], int)

Derefernce an element from the array or return the default value for that type if the index is outside the array.

public static T? Safe<T>(this T[] arr, int index)

Parameters

arr T[]
index int

Returns

T

Type Parameters

T

Safe<T, U>(IDictionary<T, U>, T)

Dereference an element form the dictionary or return the default value for the type if the key is not in the dictionary.

public static U? Safe<T, U>(this IDictionary<T, U> dict, T key)

Parameters

dict IDictionary<T, U>
key T

Returns

U

Type Parameters

T
U

Safe<T, U>(T, Func<T, U>)

Try to execution the function and return the value. Return the default value otherwise.

public static U? Safe<T, U>(this T value, Func<T, U> getter)

Parameters

value T
getter Func<T, U>

Returns

U

Type Parameters

T
U

Touch<T>(T, Action<T>)

Perform some action with the this object and then return that same object.

public static T Touch<T>(this T element, Action<T> action)

Parameters

element T
action Action<T>

Returns

T

Type Parameters

T

Transform<T, U>(T, Func<T, U>)

Convert the element to a new element.

public static U Transform<T, U>(this T value, Func<T, U> transformation)

Parameters

value T
transformation Func<T, U>

Returns

U

Type Parameters

T
U

With<T, U>(T, U)

Create a tuple with the this element and the other element.

public static (T, U) With<T, U>(this T value, U other)

Parameters

value T
other U

Returns

(T, U)

Type Parameters

T
U