Make `ModelBinderAttribute.BindingSource` setter `protected`
- #3428 - the `public` setter was not useful when this class is used as an attribute - make property `virtual` to support other override patterns - update existing test to use both override patterns
This commit is contained in:
parent
a420af67b7
commit
45ff0a269c
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public Type BinderType { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public BindingSource BindingSource
|
||||
public virtual BindingSource BindingSource
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
return _bindingSource;
|
||||
}
|
||||
set
|
||||
protected set
|
||||
{
|
||||
_bindingSource = value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,8 +108,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
|
|||
// Arrange
|
||||
var attributes = new object[]
|
||||
{
|
||||
new ModelBinderAttribute() { BindingSource = BindingSource.Body },
|
||||
new ModelBinderAttribute() { BindingSource = BindingSource.Query },
|
||||
new BindingSourceModelBinderAttribute(BindingSource.Body),
|
||||
new BindingSourceModelBinderAttribute(BindingSource.Query),
|
||||
};
|
||||
|
||||
var context = new BindingMetadataProviderContext(
|
||||
|
|
@ -132,8 +132,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
|
|||
var attributes = new object[]
|
||||
{
|
||||
new ModelBinderAttribute(),
|
||||
new ModelBinderAttribute() { BindingSource = BindingSource.Body },
|
||||
new ModelBinderAttribute() { BindingSource = BindingSource.Query },
|
||||
new BindingSourceModelBinderAttribute(BindingSource.Body),
|
||||
new BindingSourceModelBinderAttribute(BindingSource.Query),
|
||||
};
|
||||
|
||||
var context = new BindingMetadataProviderContext(
|
||||
|
|
@ -545,5 +545,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
|
|||
private class BindRequiredOverridesInheritedBindNever : BindNeverOnClass
|
||||
{
|
||||
}
|
||||
|
||||
private class BindingSourceModelBinderAttribute : ModelBinderAttribute
|
||||
{
|
||||
public BindingSourceModelBinderAttribute(BindingSource bindingSource)
|
||||
{
|
||||
BindingSource = bindingSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
|
|
@ -39,8 +38,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
public void BinderType_SettingBindingSource_OverridesDefaultCustomBindingSource()
|
||||
{
|
||||
// Arrange
|
||||
var attribute = new ModelBinderAttribute();
|
||||
attribute.BindingSource = BindingSource.Query;
|
||||
var attribute = new FromQueryModelBinderAttribute();
|
||||
attribute.BinderType = typeof(ByteArrayModelBinder);
|
||||
|
||||
// Act
|
||||
|
|
@ -49,5 +47,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
// Assert
|
||||
Assert.Equal(BindingSource.Query, source);
|
||||
}
|
||||
|
||||
private class FromQueryModelBinderAttribute : ModelBinderAttribute
|
||||
{
|
||||
public override BindingSource BindingSource => BindingSource.Query;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue