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
TFirst value.
other
TSecond value.
Returns
- T
source
when it is greater thanother
, otherwiseother
.
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
T1Source 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
TFirst value.
other
TSecond value.
Returns
- (T Min, T Max)
source
as Min andother
as Max whensource
is less than or equal toother
, otherwiseother
as Min andsource
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
TFirst value.
other
TSecond value.
Returns
- T
source
when it is less than or equal toother
, otherwiseother
.
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
TSource 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
TSource object.
Returns
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
TSource 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
See VisitMany<T>(IEnumerable<T>, Func<T, IEnumerable<T>>) for more information.
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
TSource 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
See VisitMany<T>(IEnumerable<T>, Func<T, IEnumerable<T>>, Func<T, bool>) for more information.
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
TSource 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
TSource 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
TSource 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
TSource 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
TSource 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
TSource 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