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
sourceTFirst value.
otherTSecond value.
Returns
- T
sourcewhen it is greater thanother, otherwiseother.
Type Parameters
TValue 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
sourceT1Source object.
selectorFunc<T1, IEnumerable<T2>>Selector to invoke with
sourceas its parameter.
Returns
- IMemoizedCollection<T2>
New IMemoizedCollection<T> instance.
Type Parameters
T1Source object type.
T2Collection 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
sourceTFirst value.
otherTSecond value.
Returns
- (T Min, T Max)
sourceas Min andotheras Max whensourceis less than or equal toother, otherwiseotheras Min andsourceas Max.
Type Parameters
TValue 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
sourceTFirst value.
otherTSecond value.
Returns
- T
sourcewhen it is less than or equal toother, otherwiseother.
Type Parameters
TValue 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
sourceTSource object.
Returns
- T?
New Nullable<T> instance.
Type Parameters
TObject 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
sourceTSource object.
Returns
Type Parameters
TObject 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
sourceTSource object to start from.
nodeRangeSelectorFunc<T, IEnumerable<T>>Descendant node range selector.
Returns
- IEnumerable<T>
New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal.
sourceobject is included.
Type Parameters
TObject 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
sourceTSource object to start from.
nodeRangeSelectorFunc<T, IEnumerable<T>>Descendant node range selector.
stopPredicateFunc<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.
sourceobject is included.
Type Parameters
TObject 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
sourceTSource object to start from.
nodeRangeSelectorFunc<T, IEnumerable<T>>Descendant node range selector.
Returns
- IEnumerable<T>
New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal.
sourceobject is not included.
Type Parameters
TObject 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
sourceTSource object to start from.
nodeRangeSelectorFunc<T, IEnumerable<T>>Descendant node range selector.
stopPredicateFunc<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.
sourceobject is not included.
Type Parameters
TObject 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
sourceTSource object to start from.
nodeSelectorFunc<T, T>Descendant node selector.
Returns
- IEnumerable<T>
New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal.
sourceobject is included.
Type Parameters
TObject 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
sourceTSource object to start from.
nodeSelectorFunc<T, T>Descendant node selector.
breakPredicateFunc<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.
sourceobject is included.
Type Parameters
TObject 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
sourceTSource object to start from.
nodeSelectorFunc<T, T>Descendant node selector.
Returns
- IEnumerable<T>
New IEnumerable<T> instance that contains all recursively visited objects, in order of traversal.
sourceobject is not included.
Type Parameters
TObject 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
sourceTSource object to start from.
nodeSelectorFunc<T, T>Descendant node selector.
breakPredicateFunc<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.
sourceobject is not included.
Type Parameters
TObject type.
- See Also