Update ModelBinderAttribute not throw exceptions from BinderType property setter
This commit is contained in:
parent
852d6402eb
commit
9daf6b48a1
|
|
@ -26,39 +26,17 @@ namespace Microsoft.AspNet.Mvc
|
|||
Inherited = true)]
|
||||
public class ModelBinderAttribute : Attribute, IModelNameProvider, IBinderTypeProviderMetadata
|
||||
{
|
||||
private Type _binderType;
|
||||
private BindingSource _bindingSource;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Type BinderType
|
||||
{
|
||||
get
|
||||
{
|
||||
return _binderType;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (!typeof(IModelBinder).IsAssignableFrom(value))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
Resources.FormatBinderType_MustBeIModelBinder(
|
||||
value.FullName,
|
||||
typeof(IModelBinder).FullName));
|
||||
}
|
||||
}
|
||||
|
||||
_binderType = value;
|
||||
}
|
||||
}
|
||||
public Type BinderType { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public BindingSource BindingSource
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_bindingSource == null && _binderType != null)
|
||||
if (_bindingSource == null && BinderType != null)
|
||||
{
|
||||
return BindingSource.Custom;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,23 +8,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
{
|
||||
public class ModelBinderAttributeTest
|
||||
{
|
||||
[Fact]
|
||||
public void InvalidBinderType_Throws()
|
||||
{
|
||||
// Arrange
|
||||
var attribute = new ModelBinderAttribute();
|
||||
|
||||
var expected =
|
||||
$"The type 'System.String' must implement '{typeof(IModelBinder).FullName}' " +
|
||||
"to be used as a model binder.";
|
||||
|
||||
// Act
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => { attribute.BinderType = typeof(string); });
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoBinderType_NoBindingSource()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue