Table of Contents

Class ObjectExtensions

Namespace
LfrlAnvil.Extensions
Assembly
LfrlAnvil.Core.dll

Contains various object extension methods.

public static class ObjectExtensions
Inheritance
ObjectExtensions
Inherited Members

Methods

Max<T>(T, T)

Returns the greater value out of the two.

[Pure]
public static T Max<T>(this T source, T other) where T : IComparable<T>

Parameters

source T

First value.

other T

Second value.

Returns

T

source when it is greater than other, otherwise other.

Type Parameters

T

Value type.

Memoize<T1, T2>(T1, Func<T1, IEnumerable<T2>>)

Creates a new IMemoizedCollection<T> instance from the result of selector invocation with source as its parameter.

[Pure]
public static IMemoizedCollection<T2> Memoize<T1, T2>(this T1 source, Func<T1, IEnumerable<T2>> selector)

Parameters

source T1

Source object.

selector Func<T1, IEnumerable<T2>>

Selector to invoke with source as its parameter.

Returns

IMemoizedCollection<T2>

New IMemoizedCollection<T> instance.

Type Parameters

T1

Source object type.

T2

Collection element type.

MinMax<T>(T, T)

Splits the two provided values into lesser and greater.

[Pure]
public static (T Min, T Max) MinMax<T>(this T source, T other) where T : IComparable<T>

Parameters

source T

First value.

other T

Second value.

Returns

(T Min, T Max)

source as Min and other as Max when source is less than or equal to other, otherwise other as Min and source as Max.

Type Parameters

T

Value type.

Min<T>(T, T)

Returns the lesser value out of the two.

[Pure]
public static T Min<T>(this T source, T other) where T : IComparable<T>

Parameters

source T

First value.

other T

Second value.

Returns

T

source when it is less than or equal to other, otherwise other.

Type Parameters

T

Value type.

ToNullable<T>(T)

Creates a new Nullable<T> instance from the given non-null source.

[Pure]
public static T? ToNullable<T>(this T source) where T : struct

Parameters

source T

Source object.

Returns

T?

New Nullable<T> instance.

Type Parameters

T

Object type.

ToRef<T>(T)

Creates a new Ref<T> instance from the given source.

[Pure]
public static Ref<T> ToRef<T>(this T source)

Parameters

source T

Source object.

Returns

Ref<T>

New Ref<T> instance.

Type Parameters

T

Object type.

VisitManyWithSelf<T>(T, Func<T, IEnumerable<T>>)

Recursively visits an object graph, where next objects to visit are calculated by invoking the specified nodeRangeSelector with current object as its parameter, starting with the given source.

[Pure]
public static IEnumerable<T> VisitManyWithSelf<T>(this T source, Func<T, IEnumerable<T>> nodeRangeSelector)

Parameters

source T

Source object to start from.

nodeRangeSelector Func<T, IEnumerable<T>>

Descendant node range selector.

Returns

IEnumerable<T>

New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal. source object is included.

Type Parameters

T

Object type.

Remarks

VisitManyWithSelf<T>(T, Func<T, IEnumerable<T>>, Func<T, bool>)

Recursively visits an object graph, where next objects to visit are calculated by invoking the specified nodeRangeSelector with current object as its parameter, starting with the given source.

[Pure]
public static IEnumerable<T> VisitManyWithSelf<T>(this T source, Func<T, IEnumerable<T>> nodeRangeSelector, Func<T, bool> stopPredicate)

Parameters

source T

Source object to start from.

nodeRangeSelector Func<T, IEnumerable<T>>

Descendant node range selector.

stopPredicate Func<T, bool>

Predicate that stops the traversal for the given sub-graph, when it returns true.

Returns

IEnumerable<T>

New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal. source object is included.

Type Parameters

T

Object type.

Remarks

VisitMany<T>(T, Func<T, IEnumerable<T>>)

Recursively visits an object graph, where next objects to visit are calculated by invoking the specified nodeRangeSelector with current object as its parameter, starting with the given source.

[Pure]
public static IEnumerable<T> VisitMany<T>(this T source, Func<T, IEnumerable<T>> nodeRangeSelector)

Parameters

source T

Source object to start from.

nodeRangeSelector Func<T, IEnumerable<T>>

Descendant node range selector.

Returns

IEnumerable<T>

New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal. source object is not included.

Type Parameters

T

Object type.

See Also

VisitMany<T>(T, Func<T, IEnumerable<T>>, Func<T, bool>)

Recursively visits an object graph, where next objects to visit are calculated by invoking the specified nodeRangeSelector with current object as its parameter, starting with the given source.

[Pure]
public static IEnumerable<T> VisitMany<T>(this T source, Func<T, IEnumerable<T>> nodeRangeSelector, Func<T, bool> stopPredicate)

Parameters

source T

Source object to start from.

nodeRangeSelector Func<T, IEnumerable<T>>

Descendant node range selector.

stopPredicate Func<T, bool>

Predicate that stops the traversal for the given sub-graph, when it returns true.

Returns

IEnumerable<T>

New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal. source object is not included.

Type Parameters

T

Object type.

See Also

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

Recursively visits a chain of objects, where next object in the chain is calculated by invoking the specified nodeSelector with current object as its parameter, starting with the given source. Traversal ends when nodeSelector returns null, or when source is null.

[Pure]
public static IEnumerable<T> VisitWithSelf<T>(this T? source, Func<T, T?> nodeSelector) where T : class

Parameters

source T

Source object to start from.

nodeSelector Func<T, T>

Descendant node selector.

Returns

IEnumerable<T>

New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal. source object is included.

Type Parameters

T

Object type.

VisitWithSelf<T>(T, Func<T, T>, Func<T, bool>)

Recursively visits a chain of objects, where next object in the chain is calculated by invoking the specified nodeSelector with current object as its parameter, starting with the given source. Traversal ends when the breakPredicate returns true.

[Pure]
public static IEnumerable<T> VisitWithSelf<T>(this T source, Func<T, T> nodeSelector, Func<T, bool> breakPredicate)

Parameters

source T

Source object to start from.

nodeSelector Func<T, T>

Descendant node selector.

breakPredicate Func<T, bool>

Predicate that ends the traversal when it returns true.

Returns

IEnumerable<T>

New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal. source object is included.

Type Parameters

T

Object type.

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

Recursively visits a chain of objects, where next object in the chain is calculated by invoking the specified nodeSelector with current object as its parameter, starting with the given source. Traversal ends when nodeSelector returns null, or when source is null.

[Pure]
public static IEnumerable<T> Visit<T>(this T? source, Func<T, T?> nodeSelector) where T : class

Parameters

source T

Source object to start from.

nodeSelector Func<T, T>

Descendant node selector.

Returns

IEnumerable<T>

New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal. source object is not included.

Type Parameters

T

Object type.

See Also

Visit<T>(T, Func<T, T>, Func<T, bool>)

Recursively visits a chain of objects, where next object in the chain is calculated by invoking the specified nodeSelector with current object as its parameter, starting with the given source. Traversal ends when the breakPredicate returns true.

[Pure]
public static IEnumerable<T> Visit<T>(this T source, Func<T, T> nodeSelector, Func<T, bool> breakPredicate)

Parameters

source T

Source object to start from.

nodeSelector Func<T, T>

Descendant node selector.

breakPredicate Func<T, bool>

Predicate that ends the traversal when it returns true.

Returns

IEnumerable<T>

New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal. source object is not included.

Type Parameters

T

Object type.

See Also