Class QueryFieldAttribute
Specifies that a parameter of a controller method will receive the value of a field, obtained by deserializing a request URL query.
The parameter carrying this attribute can be either a simple type or a one-dimension array.
If multiple values are present for the field, a non-array parameter will receive the last specified value, while an array parameter will receive an array of field values converted to the element type of the parameter.
If a single value is present for the field, a non-array parameter will receive the value converted to the type of the parameter, while an array parameter will receive an array of length 1, containing the value converted to the element type of the parameter
If no values are present for the field and the BadRequestIfMissing property is
true, a 400 Bad Request
response will be sent to the client, with a message
specifying the name of the missing field.
If no values are present for the field and the BadRequestIfMissing property is false, a non-array parameter will receive the default value for its type, while an array parameter will receive an array of length 0.
This class cannot be inherited.
Implements
Namespace: EmbedIO.WebApi
Syntax
public sealed class QueryFieldAttribute : Attribute, IRequestDataAttribute<WebApiController, string>, INonNullRequestDataAttribute<WebApiController, string[]>, IRequestDataAttribute<WebApiController>
Constructors
QueryFieldAttribute()
Initializes a new instance of the QueryFieldAttribute class. The name of the query field to extract will be equal to the name of the parameter carrying this attribute.
Declaration
public QueryFieldAttribute()
QueryFieldAttribute(Boolean)
Initializes a new instance of the QueryFieldAttribute class. The name of the query field to extract will be equal to the name of the parameter carrying this attribute.
Declaration
public QueryFieldAttribute(bool badRequestIfMissing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | badRequestIfMissing | If set to true, a |
QueryFieldAttribute(String)
Initializes a new instance of the QueryFieldAttribute class.
Declaration
public QueryFieldAttribute(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
String | fieldName | The name of the query field to extract. |
QueryFieldAttribute(String, Boolean)
Initializes a new instance of the QueryFieldAttribute class.
Declaration
public QueryFieldAttribute(string fieldName, bool badRequestIfMissing)
Parameters
Type | Name | Description |
---|---|---|
String | fieldName | The name of the query field to extract. |
Boolean | badRequestIfMissing | If set to true, a |
Properties
BadRequestIfMissing
Gets or sets a value indicating whether to send a 400 Bad Request
response
to the client if the URL query contains no values for the field.
If this property is true and the URL query
contains no values for the field, the 400 Bad Request
response sent
to the client will contain a reference to the missing field.
If this property is false and the URL query contains no values for the field, the default value for the parameter (or a zero-length array if the parameter is of an array type) will be passed to the controller method.
Declaration
public bool BadRequestIfMissing { get; }
Property Value
Type | Description |
---|---|
Boolean |
FieldName
Gets the name of the query field that this attribute will extract, or null if the name of the parameter carrying this attribute is to be used as field name.
Declaration
public string FieldName { get; }
Property Value
Type | Description |
---|---|
String |
Explicit Interface Implementations
INonNullRequestDataAttribute<WebApiController, String[]>.GetRequestDataAsync(WebApiController, String)
Declaration
Task<string[]> INonNullRequestDataAttribute<WebApiController, string[]>.GetRequestDataAsync(WebApiController controller, string parameterName)
Parameters
Type | Name | Description |
---|---|---|
WebApiController | controller | |
String | parameterName |
Returns
Type | Description |
---|---|
Task<String[]> |
IRequestDataAttribute<WebApiController, String>.GetRequestDataAsync(WebApiController, String)
Declaration
Task<string> IRequestDataAttribute<WebApiController, string>.GetRequestDataAsync(WebApiController controller, string parameterName)
Parameters
Type | Name | Description |
---|---|---|
WebApiController | controller | |
String | parameterName |
Returns
Type | Description |
---|---|
Task<String> |
IRequestDataAttribute<WebApiController>.GetRequestDataAsync(WebApiController, Type, String)
Declaration
Task<object> IRequestDataAttribute<WebApiController>.GetRequestDataAsync(WebApiController controller, Type type, string parameterName)
Parameters
Type | Name | Description |
---|---|---|
WebApiController | controller | |
Type | type | |
String | parameterName |
Returns
Type | Description |
---|---|
Task<Object> |