Update ModelBinderAttribute not throw exceptions from BinderType property setter

This commit is contained in:
Youngjune Hong 2015-04-14 17:31:50 -07:00
parent 852d6402eb
commit 9daf6b48a1
2 changed files with 2 additions and 41 deletions

View File

@ -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;
}

View File

@ -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()
{