Table of Contents

Class ListPatternExtensions

Namespace
Garyon.Extensions
Assembly
Garyon.dll

Provides extensions for commonly-known types using list patterns.

public static class ListPatternExtensions
Inheritance
ListPatternExtensions
Inherited Members

Methods

TryGetSingle<TBase, TDerived>(IReadOnlyList<TBase>, out TDerived?)

Tries to get a single element from the given read-only list of a specified type.

public static bool TryGetSingle<TBase, TDerived>(this IReadOnlyList<TBase> list, out TDerived? single) where TDerived : TBase

Parameters

list IReadOnlyList<TBase>

The read-only list whose elements to evaluate.

single TDerived

The single element of the specified type to get. If the list does not contain a single element, or the single element is not of the specified type, this is default.

Returns

bool

true if the list only contains a single element that is of type TDerived, otherwise false.

Type Parameters

TBase

The type of the elements in the list.

TDerived

The type of the single element that must be matched.

TryGetSingle<TBase, TDerived>(ReadOnlySpan<TBase>, out TDerived?)

Tries to get a single element from the given read-only span of a specified type.

public static bool TryGetSingle<TBase, TDerived>(this ReadOnlySpan<TBase> span, out TDerived? single) where TDerived : TBase

Parameters

span ReadOnlySpan<TBase>

The read-only span whose elements to evaluate.

single TDerived

The single element of the specified type to get. If the span does not contain a single element, or the single element is not of the specified type, this is default.

Returns

bool

true if the span only contains a single element that is of type TDerived, otherwise false.

Type Parameters

TBase

The type of the elements in the span.

TDerived

The type of the single element that must be matched.

TryGetSingle<TBase, TDerived>(Span<TBase>, out TDerived?)

Tries to get a single element from the given span of a specified type.

public static bool TryGetSingle<TBase, TDerived>(this Span<TBase> span, out TDerived? single) where TDerived : TBase

Parameters

span Span<TBase>

The span whose elements to evaluate.

single TDerived

The single element of the specified type to get. If the span does not contain a single element, or the single element is not of the specified type, this is default.

Returns

bool

true if the span only contains a single element that is of type TDerived, otherwise false.

Type Parameters

TBase

The type of the elements in the span.

TDerived

The type of the single element that must be matched.

TryGetSingle<TBase, TDerived>(TBase[], out TDerived?)

Tries to get a single element from the given array of a specified type.

public static bool TryGetSingle<TBase, TDerived>(this TBase[] array, out TDerived? single) where TDerived : TBase

Parameters

array TBase[]

The array whose elements to evaluate.

single TDerived

The single element of the specified type to get. If the array does not contain a single element, or the single element is not of the specified type, this is default.

Returns

bool

true if the array only contains a single element that is of type TDerived, otherwise false.

Type Parameters

TBase

The type of the elements in the array.

TDerived

The type of the single element that must be matched.