blob: eff97767d1b64c111f517f79b3aaf0a9dbb4cab2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Metadata;
namespace System.Web.Http.Controllers
{
/// <summary>
/// Describes how a parameter is bound. The binding should be static (based purely on the descriptor) and
/// can be shared across requests.
/// </summary>
public abstract class HttpParameterBinding
{
private readonly HttpParameterDescriptor _descriptor;
protected HttpParameterBinding(HttpParameterDescriptor descriptor)
{
if (descriptor == null)
{
throw Error.ArgumentNull("descriptor");
}
_descriptor = descriptor;
}
/// <summary>
/// True iff this binding owns the body. This is important since the body can be a stream that is only read once.
/// This lets us know who is trying to read the body, and enforce that there is only one reader.
/// </summary>
public virtual bool WillReadBody
{
get { return false; }
}
/// <summary>
/// True if the binding was successful and ExecuteBinding can be called.
/// False if there was an error determining this binding. This means a developer error somewhere, such as
/// configuration, parameter types, proper attributes, etc.
/// </summary>
public bool IsValid
{
get { return ErrorMessage == null; }
}
/// <summary>
/// Get an error message describing why this binding is invalid.
/// </summary>
public virtual string ErrorMessage
{
get { return null; }
}
public HttpParameterDescriptor Descriptor
{
get { return _descriptor; }
}
/// <summary>
/// Execute the binding for the given request.
/// On success, this will add the parameter to the actionContext.ActionArguments dictionary.
/// Caller ensures <see cref="IsValid"/> is true.
/// </summary>
/// <param name="metadataProvider">metadata provider to use for validation.</param>
/// <param name="actionContext">action context for the binding. This contains the parameter dictionary that will get populated.</param>
/// <param name="cancellationToken">Cancellation token for cancelling the binding operation. Or a binder can also bind a parameter to this.</param>
/// <returns>Task that is signaled when the binding is complete. For simple bindings from a URI, this should be signalled immediately.
/// For bindings that read the content body, this may do network IO.</returns>
public abstract Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken);
}
}
|