Class Extensions
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)otherV
Returns
- (T, U, V)
Type Parameters
TUV
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)otherW
Returns
- (T, U, V, W)
Type Parameters
TUVW
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
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
valueobject
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)expanderFunc<U, (U, V)>
Returns
- (T, U, V)
Type Parameters
TUV
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)expanderFunc<V, (V, W)>
Returns
- (T, U, V, W)
Type Parameters
TUVW
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
valueTfieldNamestring
Returns
- T
Type Parameters
T
Exceptions
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
valueTdefaultFuncFunc<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
valueTdefaultValueT
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
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
arrT[]indexint
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
dictIDictionary<T, U>keyT
Returns
- U
Type Parameters
TU
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
valueTgetterFunc<T, U>
Returns
- U
Type Parameters
TU
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
elementTactionAction<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
valueTtransformationFunc<T, U>
Returns
- U
Type Parameters
TU
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
valueTotherU
Returns
- (T, U)
Type Parameters
TU