Class RequestDependentResultWriter<TModel, TUser>
A result writer that chooses how to format the result based on the request
Inheritance
Implements
Namespace: Seltzr.Results
Assembly: Seltzr.dll
Syntax
public abstract class RequestDependentResultWriter<TModel, TUser> : IResultWriter<TModel, TUser> where TModel : class where TUser : class
Type Parameters
TModel
The type of model to format
TUser
The type of user context
Remarks
Though perhaps this class is a little confusing at first, it helps to know that this class forms the basis for the QueryDependentResultWriter<TModel, TUser>, HeaderDependentResultWriter<TModel, TUser>, and like classes.
Constructors
RequestDependentResultWriter(String[], IResultWriter<TModel, TUser>[], Int32, Boolean)
Initializes a new instance of the RequestDependentResultWriter<TModel, TUser> class.
protected RequestDependentResultWriter(string[] values, IResultWriter<TModel, TUser>[] writers, int defaultIndex = -1, bool caseSensitive = false)
Parameters
values
String[]
The values of the request property that should determine which result writer to use
writers
IResultWriter<TModel, TUser>[]
The result writers to use, indexed in the same order as values
defaultIndex
Int32
The index of the default result writer to use, or -1 if an error should be thrown if no values match
caseSensitive
Boolean
true if the parameter values are case sensitive, false otherwise
Methods
Gets whether or not this IResultWriter<TModel, TUser> can write a result for the given request
public virtual Task<bool> CanWriteAsync(HttpRequest request)
Parameters
request
HttpRequest
The request to test if a result can be written for it
Returns
true if a result can be written for request
, false otherwise
Gets the value of the request parameter this RequestDependentResultWriter<TModel, TUser> switches on
protected abstract string GetRequestParameterValue(HttpRequest request)
Parameters
request
HttpRequest
The request context to use to get the parameter value
Returns
The value of the request parameter to switch on
WriteResultAsync(IApiContext<TModel, TUser>, IEnumerable<TModel>, FormattingOptions)
Formats the API result
public virtual Task WriteResultAsync(IApiContext<TModel, TUser> context, IEnumerable<TModel> data, FormattingOptions options)
Parameters
context
IApiContext<TModel, TUser>
The current API context
data
IEnumerable<TModel>
The dataset to format
options
FormattingOptions
Options for formatting the result
Returns
When the result has been sent