Removing BodyParameterInfo and ParameterBindingInfo
These have been superceded by the BinderMetadata property on ParameterDescriptor.
This commit is contained in:
parent
61f218c8e4
commit
557974b948
|
|
@ -1,17 +0,0 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
|
||||||
{
|
|
||||||
public class BodyParameterInfo
|
|
||||||
{
|
|
||||||
public BodyParameterInfo(Type parameterType)
|
|
||||||
{
|
|
||||||
ParameterType = parameterType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type ParameterType { get; private set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -513,21 +513,9 @@ namespace Microsoft.AspNet.Mvc
|
||||||
BinderMetadata = parameter.BinderMetadata,
|
BinderMetadata = parameter.BinderMetadata,
|
||||||
IsOptional = parameter.IsOptional,
|
IsOptional = parameter.IsOptional,
|
||||||
Name = parameter.ParameterName,
|
Name = parameter.ParameterName,
|
||||||
|
ParameterType = parameter.ParameterInfo.ParameterType,
|
||||||
};
|
};
|
||||||
|
|
||||||
var isFromBody = parameter.Attributes.OfType<FromBodyAttribute>().Any();
|
|
||||||
if (isFromBody)
|
|
||||||
{
|
|
||||||
parameterDescriptor.BodyParameterInfo = new BodyParameterInfo(
|
|
||||||
parameter.ParameterInfo.ParameterType);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
parameterDescriptor.ParameterBindingInfo = new ParameterBindingInfo(
|
|
||||||
parameter.ParameterName,
|
|
||||||
parameter.ParameterInfo.ParameterType);
|
|
||||||
}
|
|
||||||
|
|
||||||
return parameterDescriptor;
|
return parameterDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Mvc.Description
|
||||||
// Process together parameters that appear on the path template and on the
|
// Process together parameters that appear on the path template and on the
|
||||||
// action descriptor and do not come from the body.
|
// action descriptor and do not come from the body.
|
||||||
TemplatePart templateParameter = null;
|
TemplatePart templateParameter = null;
|
||||||
if (parameter.BodyParameterInfo == null)
|
if (parameter.BinderMetadata as IFormatterBinderMetadata == null)
|
||||||
{
|
{
|
||||||
templateParameter = templateParameters
|
templateParameter = templateParameters
|
||||||
.FirstOrDefault(p => p.Name.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase));
|
.FirstOrDefault(p => p.Name.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
@ -266,18 +266,16 @@ namespace Microsoft.AspNet.Mvc.Description
|
||||||
IsOptional = parameter.IsOptional,
|
IsOptional = parameter.IsOptional,
|
||||||
Name = parameter.Name,
|
Name = parameter.Name,
|
||||||
ParameterDescriptor = parameter,
|
ParameterDescriptor = parameter,
|
||||||
|
Type = parameter.ParameterType,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (parameter.ParameterBindingInfo != null)
|
if (parameter.BinderMetadata as IFormatterBinderMetadata != null)
|
||||||
|
{
|
||||||
|
resourceParameter.Source = ApiParameterSource.Body;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
resourceParameter.Source = ApiParameterSource.Query;
|
resourceParameter.Source = ApiParameterSource.Query;
|
||||||
resourceParameter.Type = parameter.ParameterBindingInfo.ParameterType;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameter.BodyParameterInfo != null)
|
|
||||||
{
|
|
||||||
resourceParameter.Type = parameter.BodyParameterInfo.ParameterType;
|
|
||||||
resourceParameter.Source = ApiParameterSource.Body;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resourceParameter;
|
return resourceParameter;
|
||||||
|
|
@ -295,13 +293,9 @@ namespace Microsoft.AspNet.Mvc.Description
|
||||||
ParameterDescriptor = parameter,
|
ParameterDescriptor = parameter,
|
||||||
Constraint = templateParameter.InlineConstraint,
|
Constraint = templateParameter.InlineConstraint,
|
||||||
DefaultValue = templateParameter.DefaultValue,
|
DefaultValue = templateParameter.DefaultValue,
|
||||||
|
Type = parameter.ParameterType,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (parameter.ParameterBindingInfo != null)
|
|
||||||
{
|
|
||||||
resourceParameter.Type = parameter.ParameterBindingInfo.ParameterType;
|
|
||||||
}
|
|
||||||
|
|
||||||
return resourceParameter;
|
return resourceParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
|
||||||
{
|
|
||||||
public class ParameterBindingInfo
|
|
||||||
{
|
|
||||||
public ParameterBindingInfo(string prefix, Type parameterType)
|
|
||||||
{
|
|
||||||
Prefix = prefix;
|
|
||||||
ParameterType = parameterType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Prefix { get; private set; }
|
|
||||||
|
|
||||||
public Type ParameterType { get; private set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
namespace Microsoft.AspNet.Mvc
|
||||||
|
|
@ -15,10 +14,6 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
public Type ParameterType { get; set; }
|
public Type ParameterType { get; set; }
|
||||||
|
|
||||||
public ParameterBindingInfo ParameterBindingInfo { get; set; }
|
|
||||||
|
|
||||||
public IBinderMetadata BinderMetadata { get; set; }
|
public IBinderMetadata BinderMetadata { get; set; }
|
||||||
|
|
||||||
public BodyParameterInfo BodyParameterInfo { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
if ((parameter.BinderMetadata is IRouteDataValueProviderMetadata ||
|
if ((parameter.BinderMetadata is IRouteDataValueProviderMetadata ||
|
||||||
parameter.BinderMetadata is IQueryValueProviderMetadata) &&
|
parameter.BinderMetadata is IQueryValueProviderMetadata) &&
|
||||||
!parameter.IsOptional &&
|
!parameter.IsOptional &&
|
||||||
ValueProviderResult.CanConvertFromString(parameter.ParameterBindingInfo.ParameterType))
|
ValueProviderResult.CanConvertFromString(parameter.ParameterType))
|
||||||
{
|
{
|
||||||
var nameProvider = parameter.BinderMetadata as IModelNameProvider;
|
var nameProvider = parameter.BinderMetadata as IModelNameProvider;
|
||||||
var prefix = nameProvider?.Name ?? parameter.Name;
|
var prefix = nameProvider?.Name ?? parameter.Name;
|
||||||
|
|
|
||||||
|
|
@ -127,11 +127,8 @@ namespace Microsoft.AspNet.Mvc.Test
|
||||||
|
|
||||||
Assert.Equal("id", id.Name);
|
Assert.Equal("id", id.Name);
|
||||||
Assert.False(id.IsOptional);
|
Assert.False(id.IsOptional);
|
||||||
Assert.Null(id.BodyParameterInfo);
|
Assert.Null(id.BinderMetadata);
|
||||||
|
Assert.Equal(typeof(int), id.ParameterType);
|
||||||
Assert.NotNull(id.ParameterBindingInfo);
|
|
||||||
Assert.Equal("id", id.ParameterBindingInfo.Prefix);
|
|
||||||
Assert.Equal(typeof(int), id.ParameterBindingInfo.ParameterType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -150,20 +147,15 @@ namespace Microsoft.AspNet.Mvc.Test
|
||||||
|
|
||||||
Assert.Equal("id", id.Name);
|
Assert.Equal("id", id.Name);
|
||||||
Assert.False(id.IsOptional);
|
Assert.False(id.IsOptional);
|
||||||
Assert.Null(id.BodyParameterInfo);
|
Assert.Null(id.BinderMetadata);
|
||||||
|
Assert.Equal(typeof(int), id.ParameterType);
|
||||||
Assert.NotNull(id.ParameterBindingInfo);
|
|
||||||
Assert.Equal("id", id.ParameterBindingInfo.Prefix);
|
|
||||||
Assert.Equal(typeof(int), id.ParameterBindingInfo.ParameterType);
|
|
||||||
|
|
||||||
var entity = Assert.Single(main.Parameters, p => p.Name == "entity");
|
var entity = Assert.Single(main.Parameters, p => p.Name == "entity");
|
||||||
|
|
||||||
Assert.Equal("entity", entity.Name);
|
Assert.Equal("entity", entity.Name);
|
||||||
Assert.False(entity.IsOptional);
|
Assert.False(entity.IsOptional);
|
||||||
Assert.Null(entity.ParameterBindingInfo);
|
Assert.IsType<FromBodyAttribute>(entity.BinderMetadata);
|
||||||
|
Assert.Equal(typeof(TestActionParameter), entity.ParameterType);
|
||||||
Assert.NotNull(entity.BodyParameterInfo);
|
|
||||||
Assert.Equal(typeof(TestActionParameter), entity.BodyParameterInfo.ParameterType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -182,31 +174,22 @@ namespace Microsoft.AspNet.Mvc.Test
|
||||||
|
|
||||||
Assert.Equal("id", id.Name);
|
Assert.Equal("id", id.Name);
|
||||||
Assert.False(id.IsOptional);
|
Assert.False(id.IsOptional);
|
||||||
Assert.Null(id.BodyParameterInfo);
|
Assert.Null(id.BinderMetadata);
|
||||||
|
Assert.Equal(typeof(int), id.ParameterType);
|
||||||
Assert.NotNull(id.ParameterBindingInfo);
|
|
||||||
Assert.Equal("id", id.ParameterBindingInfo.Prefix);
|
|
||||||
Assert.Equal(typeof(int), id.ParameterBindingInfo.ParameterType);
|
|
||||||
|
|
||||||
var upperCaseId = Assert.Single(main.Parameters, p => p.Name == "ID");
|
var upperCaseId = Assert.Single(main.Parameters, p => p.Name == "ID");
|
||||||
|
|
||||||
Assert.Equal("ID", upperCaseId.Name);
|
Assert.Equal("ID", upperCaseId.Name);
|
||||||
Assert.False(upperCaseId.IsOptional);
|
Assert.False(upperCaseId.IsOptional);
|
||||||
Assert.Null(upperCaseId.BodyParameterInfo);
|
Assert.Null(upperCaseId.BinderMetadata);
|
||||||
|
Assert.Equal(typeof(int), upperCaseId.ParameterType);
|
||||||
Assert.NotNull(upperCaseId.ParameterBindingInfo);
|
|
||||||
Assert.Equal("ID", upperCaseId.ParameterBindingInfo.Prefix);
|
|
||||||
Assert.Equal(typeof(int), upperCaseId.ParameterBindingInfo.ParameterType);
|
|
||||||
|
|
||||||
var pascalCaseId = Assert.Single(main.Parameters, p => p.Name == "Id");
|
var pascalCaseId = Assert.Single(main.Parameters, p => p.Name == "Id");
|
||||||
|
|
||||||
Assert.Equal("Id", pascalCaseId.Name);
|
Assert.Equal("Id", pascalCaseId.Name);
|
||||||
Assert.False(pascalCaseId.IsOptional);
|
Assert.False(pascalCaseId.IsOptional);
|
||||||
Assert.Null(pascalCaseId.BodyParameterInfo);
|
Assert.Null(id.BinderMetadata);
|
||||||
|
Assert.Equal(typeof(int), pascalCaseId.ParameterType);
|
||||||
Assert.NotNull(pascalCaseId.ParameterBindingInfo);
|
|
||||||
Assert.Equal("Id", pascalCaseId.ParameterBindingInfo.Prefix);
|
|
||||||
Assert.Equal(typeof(int), pascalCaseId.ParameterBindingInfo.ParameterType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -229,11 +212,8 @@ namespace Microsoft.AspNet.Mvc.Test
|
||||||
|
|
||||||
Assert.Equal("id", id.Name);
|
Assert.Equal("id", id.Name);
|
||||||
Assert.True(id.IsOptional);
|
Assert.True(id.IsOptional);
|
||||||
Assert.Null(id.BodyParameterInfo);
|
Assert.Null(id.BinderMetadata);
|
||||||
|
Assert.Equal(parameterType, id.ParameterType);
|
||||||
Assert.NotNull(id.ParameterBindingInfo);
|
|
||||||
Assert.Equal("id", id.ParameterBindingInfo.Prefix);
|
|
||||||
Assert.Equal(parameterType, id.ParameterBindingInfo.ParameterType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -254,11 +234,8 @@ namespace Microsoft.AspNet.Mvc.Test
|
||||||
|
|
||||||
Assert.Equal("entity", entity.Name);
|
Assert.Equal("entity", entity.Name);
|
||||||
Assert.False(entity.IsOptional);
|
Assert.False(entity.IsOptional);
|
||||||
|
Assert.IsType<FromBodyAttribute>(entity.BinderMetadata);
|
||||||
Assert.NotNull(entity.BodyParameterInfo);
|
Assert.Equal(typeof(TestActionParameter), entity.ParameterType);
|
||||||
Assert.Equal(typeof(TestActionParameter), entity.BodyParameterInfo.ParameterType);
|
|
||||||
|
|
||||||
Assert.Null(entity.ParameterBindingInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -279,11 +256,8 @@ namespace Microsoft.AspNet.Mvc.Test
|
||||||
|
|
||||||
Assert.Equal("entity", entity.Name);
|
Assert.Equal("entity", entity.Name);
|
||||||
Assert.False(entity.IsOptional);
|
Assert.False(entity.IsOptional);
|
||||||
Assert.Null(entity.BodyParameterInfo);
|
Assert.Null(entity.BinderMetadata);
|
||||||
|
Assert.Equal(typeof(TestActionParameter), entity.ParameterType);
|
||||||
Assert.NotNull(entity.ParameterBindingInfo);
|
|
||||||
Assert.Equal("entity", entity.ParameterBindingInfo.Prefix);
|
|
||||||
Assert.Equal(typeof(TestActionParameter), entity.ParameterBindingInfo.ParameterType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
||||||
|
|
@ -1348,7 +1348,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
return invoker;
|
return invoker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Invoke_UsesDefaultValuesIfNotBound()
|
public async Task Invoke_UsesDefaultValuesIfNotBound()
|
||||||
|
|
@ -1360,13 +1360,13 @@ namespace Microsoft.AspNet.Mvc
|
||||||
.DeclaredMethods
|
.DeclaredMethods
|
||||||
.First(m => m.Name.Equals("ActionMethodWithDefaultValues", StringComparison.Ordinal)),
|
.First(m => m.Name.Equals("ActionMethodWithDefaultValues", StringComparison.Ordinal)),
|
||||||
Parameters = new List<ParameterDescriptor>
|
Parameters = new List<ParameterDescriptor>
|
||||||
{
|
{
|
||||||
new ParameterDescriptor
|
new ParameterDescriptor
|
||||||
{
|
{
|
||||||
Name = "value",
|
Name = "value",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("value", typeof(int))
|
ParameterType = typeof(int),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
FilterDescriptors = new List<FilterDescriptor>()
|
FilterDescriptors = new List<FilterDescriptor>()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,12 +122,13 @@ namespace Microsoft.AspNet.Mvc.Description
|
||||||
{
|
{
|
||||||
Name = "id",
|
Name = "id",
|
||||||
IsOptional = true,
|
IsOptional = true,
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
|
BinderMetadata = new FromBodyAttribute(),
|
||||||
Name = "username",
|
Name = "username",
|
||||||
BodyParameterInfo = new BodyParameterInfo(typeof(string)),
|
ParameterType = typeof(string),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -224,7 +225,7 @@ namespace Microsoft.AspNet.Mvc.Description
|
||||||
{
|
{
|
||||||
Name = "id",
|
Name = "id",
|
||||||
IsOptional = true,
|
IsOptional = true,
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int))
|
ParameterType = typeof(int),
|
||||||
};
|
};
|
||||||
action.Parameters = new List<ParameterDescriptor> { parameterDescriptor };
|
action.Parameters = new List<ParameterDescriptor> { parameterDescriptor };
|
||||||
|
|
||||||
|
|
@ -277,9 +278,10 @@ namespace Microsoft.AspNet.Mvc.Description
|
||||||
|
|
||||||
var parameterDescriptor = new ParameterDescriptor
|
var parameterDescriptor = new ParameterDescriptor
|
||||||
{
|
{
|
||||||
|
BinderMetadata = new FromBodyAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
IsOptional = false,
|
IsOptional = false,
|
||||||
BodyParameterInfo = new BodyParameterInfo(typeof(int))
|
ParameterType = typeof(int),
|
||||||
};
|
};
|
||||||
action.Parameters = new List<ParameterDescriptor> { parameterDescriptor };
|
action.Parameters = new List<ParameterDescriptor> { parameterDescriptor };
|
||||||
|
|
||||||
|
|
@ -334,7 +336,7 @@ namespace Microsoft.AspNet.Mvc.Description
|
||||||
{
|
{
|
||||||
Name = "id",
|
Name = "id",
|
||||||
IsOptional = isDescriptorParameterOptional,
|
IsOptional = isDescriptorParameterOptional,
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int))
|
ParameterType = typeof(int),
|
||||||
};
|
};
|
||||||
action.Parameters = new List<ParameterDescriptor> { parameterDescriptor };
|
action.Parameters = new List<ParameterDescriptor> { parameterDescriptor };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,13 +37,14 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
MethodInfo = method.Method,
|
MethodInfo = method.Method,
|
||||||
Parameters = new List<ParameterDescriptor>
|
Parameters = new List<ParameterDescriptor>
|
||||||
{
|
{
|
||||||
new ParameterDescriptor
|
new ParameterDescriptor
|
||||||
{
|
{
|
||||||
Name = "foo",
|
BinderMetadata = new FromBodyAttribute(),
|
||||||
BodyParameterInfo = new BodyParameterInfo(parameterType)
|
Name = "foo",
|
||||||
}
|
ParameterType = parameterType,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var metadataProvider = new EmptyModelMetadataProvider();
|
var metadataProvider = new EmptyModelMetadataProvider();
|
||||||
|
|
@ -83,6 +84,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
new RouteData(),
|
new RouteData(),
|
||||||
actionDescriptor);
|
actionDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HttpContext GetHttpContext(byte[] contentBytes,
|
private static HttpContext GetHttpContext(byte[] contentBytes,
|
||||||
string contentType)
|
string contentType)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -172,13 +172,13 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
{
|
{
|
||||||
MethodInfo = method.Method,
|
MethodInfo = method.Method,
|
||||||
Parameters = new List<ParameterDescriptor>
|
Parameters = new List<ParameterDescriptor>
|
||||||
{
|
{
|
||||||
new ParameterDescriptor
|
new ParameterDescriptor
|
||||||
{
|
{
|
||||||
Name = "foo",
|
Name = "foo",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("foo", typeof(object))
|
ParameterType = typeof(object),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var binder = new Mock<IModelBinder>();
|
var binder = new Mock<IModelBinder>();
|
||||||
binder.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
|
binder.Setup(b => b.BindModelAsync(It.IsAny<ModelBindingContext>()))
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -54,13 +54,13 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -90,13 +90,13 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -126,13 +126,13 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -162,14 +162,14 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
IsOptional = true,
|
IsOptional = true,
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -199,13 +199,13 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -216,13 +216,13 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "quantity_ordered",
|
Name = "quantity_ordered",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity_ordered", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -256,7 +256,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -267,13 +267,13 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -304,14 +304,14 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
IsOptional = true,
|
IsOptional = true,
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -322,13 +322,13 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -359,13 +359,13 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -376,13 +376,13 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "price",
|
Name = "price",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("price", typeof(decimal)),
|
ParameterType = typeof(decimal),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -416,7 +416,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -427,14 +427,14 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
IsOptional = true,
|
IsOptional = true,
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -465,7 +465,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -476,13 +476,13 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromUriAttribute(),
|
BinderMetadata = new FromUriAttribute(),
|
||||||
Name = "id",
|
Name = "id",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("id", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
new ParameterDescriptor()
|
new ParameterDescriptor()
|
||||||
{
|
{
|
||||||
BinderMetadata = new FromBodyAttribute(),
|
BinderMetadata = new FromBodyAttribute(),
|
||||||
Name = "quantity",
|
Name = "quantity",
|
||||||
ParameterBindingInfo = new ParameterBindingInfo("quantity", typeof(int)),
|
ParameterType = typeof(int),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNet.Mvc;
|
using Microsoft.AspNet.Mvc;
|
||||||
|
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||||
|
|
||||||
namespace FormatterWebSite
|
namespace FormatterWebSite
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +15,7 @@ namespace FormatterWebSite
|
||||||
{
|
{
|
||||||
var bodyParameter = context.ActionDescriptor
|
var bodyParameter = context.ActionDescriptor
|
||||||
.Parameters
|
.Parameters
|
||||||
.FirstOrDefault(parameter => parameter.BodyParameterInfo != null);
|
.FirstOrDefault(parameter => parameter.BinderMetadata is IFormatterBinderMetadata);
|
||||||
if (bodyParameter != null)
|
if (bodyParameter != null)
|
||||||
{
|
{
|
||||||
var parameterBindingErrors = context.ModelState[bodyParameter.Name].Errors;
|
var parameterBindingErrors = context.ModelState[bodyParameter.Name].Errors;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue