Class BindingOptions
request binding options
Inheritance
Inherited Members
Namespace: FastEndpoints
Assembly: FastEndpoints.dll
Syntax
public class BindingOptions
Properties
FailureMessage
a function used to construct the failure message when a supplied value cannot be succesfully bound to a dto property during model binding. the following arguments are supplied to the function.
System.Type: the type of the property which failed to bind
System.String: the name of the property which failed to bind
Microsoft.Extensions.Primitives.StringValues: the value that was attempted which resulted in the failure
use these input parameters and construct your own error message string and return it from the function.Declaration
public Func<Type, string, StringValues, string> FailureMessage { set; }
Property Value
Type | Description |
---|---|
System.Func<System.Type, System.String, Microsoft.Extensions.Primitives.StringValues, System.String> |
Modifier
an optional action to be run after the endpoint level request binding has occured. it is intended as a way to perform common model binding logic that applies to all endpoints/requests. the action is passed in the following arguments:
System.Object: the request dto instance
System.Type: the type of the request dto
BinderContext: the request binding context
System.Threading.CancellationToken: a cancellation token
WARNING: be mindful of the performance cost of using reflection to modify the request dto object
Declaration
public Action<object, Type, BinderContext, CancellationToken> Modifier { set; }
Property Value
Type | Description |
---|---|
System.Action<System.Object, System.Type, BinderContext, System.Threading.CancellationToken> |
Methods
ValueParserFor(Type, Func<Object, ParseResult>)
add a custom value parser function for any given type which the default model binder will use to parse values when model binding request dto properties from query/route/forms/headers/claims.
this is an alternative approach to adding a TryParse()
function to your types that need model binding support from the abovementioned binding sources.
once you register a parser function here for a type, any TryParse()
method on the type will not be used for parsing.
also, these parser functions do not apply to JSON deserialization done by STJ and can be considered the equivalent to registering a custom converter in STJ when it comes to query/route/forms/headers/claims binding sources.
Declaration
public bool ValueParserFor(Type type, Func<object, ParseResult> parser)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | the type of the class which this parser function will target |
System.Func<System.Object, ParseResult> | parser | a function that takes in a nullable object and returns a ParseResult as the output.
|
Returns
Type | Description |
---|---|
System.Boolean |
ValueParserFor<T>(Func<Object, ParseResult>)
add a custom value parser function for any given type which the default model binder will use to parse values when model binding request dto properties from query/route/forms/headers/claims.
this is an alternative approach to adding a TryParse()
function to your types that need model binding support from the abovementioned binding sources.
once you register a parser function here for a type, any TryParse()
method on the type will not be used for parsing.
also, these parser functions do not apply to JSON deserialization done by STJ and can be considered the equivalent to registering a custom converter in STJ when it comes to query/route/forms/headers/claims binding sources.
Declaration
public bool ValueParserFor<T>(Func<object, ParseResult> parser)
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Object, ParseResult> | parser | a function that takes in a nullable object and returns a ParseResult as the output.
|
Returns
Type | Description |
---|---|
System.Boolean |
Type Parameters
Name | Description |
---|---|
T | the type of the class which this parser function will target |