Class MaybePrimitiveModelBinder<T>
- Namespace
- Trellis.Asp.ModelBinding
- Assembly
- Trellis.Asp.dll
Model binder for Maybe<T> parameters where T is an
STJ-native primitive in the closed allowed list defined by
SupportedPrimitives. Binds optional route, query, form, and
header parameters into Maybe<T>.
public sealed class MaybePrimitiveModelBinder<T> : IModelBinder where T : notnull
Type Parameters
TOne of: string, decimal, int, long, short, byte, double, float, bool, Guid, DateTime, DateTimeOffset.
- Inheritance
-
MaybePrimitiveModelBinder<T>
- Implements
- Inherited Members
- Extension Methods
Remarks
- Parameter absent or empty →
Maybe<T>.None(success, value not provided). - Parameter present and parsable as
T→Maybe.From(parsedValue). - Parameter present but unparsable → model-state error; result is Failed().
Closes the binder-side parity gap with MaybeScalarValueJsonConverterFactory: route /
query / header parameters typed Maybe<long> / Maybe<string> / etc.
now bind directly without a wire-shape DTO + adapter at the seam. The allowed list lives on
MaybePrimitives (non-generic) so the FrozenSet<T>
is allocated once for the entire framework rather than once per closed generic.
Methods
BindModelAsync(ModelBindingContext)
Attempts to bind a model.
public Task BindModelAsync(ModelBindingContext bindingContext)
Parameters
bindingContextModelBindingContextThe ModelBindingContext.
Returns
- Task
A Task which will complete when the model binding process completes.
If model binding was successful, the Result should have IsModelSet set to
true.A model binder that completes successfully should set Result to a value returned from Success(object).