summaryrefslogtreecommitdiff
path: root/external/aspnetwebstack/src/System.Web.Http/ModelBinding/ErrorParameterBinding.cs
blob: 8b20066583e94af8d5d4e749eae34a9955a14a8b (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
// 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.Controllers;
using System.Web.Http.Metadata;

namespace System.Web.Http.ModelBinding
{
    /// <summary>
    /// Describe a binding error.  This includes a message that can give meaningful information to a client.
    /// </summary>
    public class ErrorParameterBinding : HttpParameterBinding
    {
        private readonly string _message;

        public ErrorParameterBinding(HttpParameterDescriptor descriptor, string message)
            : base(descriptor)
        {
            if (message == null)
            {
                throw Error.ArgumentNull(message);
            }
            _message = message;
        }

        public override string ErrorMessage
        {
            get
            {
                return _message;
            }
        }

        public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)
        {
            // Caller should have already checked IsError before executing, so we shoulnd't be here. 
            return TaskHelpers.FromError(new InvalidOperationException());            
        }
    }
}