Candy.Server.Controllers.VersionParameterBinding.ExecuteBindingAsync C# (CSharp) Method

ExecuteBindingAsync() public method

Asynchronously executes the binding for the given request.
public ExecuteBindingAsync ( System.Web.Http.Metadata.ModelMetadataProvider metadataProvider, System.Web.Http.Controllers.HttpActionContext actionContext, CancellationToken cancellationToken ) : Task
metadataProvider System.Web.Http.Metadata.ModelMetadataProvider Metadata provider to use for validation.
actionContext System.Web.Http.Controllers.HttpActionContext The action context for the binding. The action context contains the parameter dictionary that will get populated with the parameter.
cancellationToken System.Threading.CancellationToken Cancellation token for cancelling the binding operation.
return Task
        public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)
        {
            // TODO: 本当はどうやってやるべきなのかがわからない…
            var queryString = new QueryStringValueProvider(actionContext, CultureInfo.CurrentCulture);
            var parameterName = Descriptor.ParameterName;
            var value = queryString.GetValue(parameterName).Maybe(x => x.AttemptedValue) ??
                        actionContext.ControllerContext.RouteData.Values[parameterName] as string;

            Version version;
            if (Version.TryParse(value, out version))
            {
                SetValue(actionContext, version);
            }

            return _completed;
        }