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