Table of Contents

Class CoercerExtensions

Namespace
PatternKit.Examples.Strategies.Coercion
Assembly
PatternKit.Examples.dll

Extension methods for Coercer<T> and strategy inspection.

public static class CoercerExtensions
Inheritance
CoercerExtensions
Inherited Members

Methods

Coerce<T>(object?)

Coerces the current value to T using From(object?).

public static T? Coerce<T>(this object? v)

Parameters

v object

The input value to coerce.

Returns

T

The coerced value when successful; otherwise default.

Type Parameters

T

The target type to coerce into.

Examples

object any = "42";
int? value = any.Coerce<int>(); // 42

GetHandlersArray<T>(TryStrategy<object, T>)

Extracts the compiled handler array from a TryStrategy<TIn, TOut> instance.

public static TryStrategy<object, T>.TryHandler[] GetHandlersArray<T>(this TryStrategy<object, T> s)

Parameters

s TryStrategy<object, T>

The strategy instance.

Returns

TryHandler[]

The compiled TryStrategy<TIn, TOut>.TryHandler array, or an empty array when unavailable.

Type Parameters

T

The output type of the strategy.

Remarks

This uses reflection to access the strategy's internal backing field. Intended for diagnostics and tests.