Revert "[Fixes #2609] Support comma separated string include in BindAttribute"
This reverts commit eba352166d.
This commit is contained in:
parent
eba352166d
commit
7746d0f451
|
|
@ -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 System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNet.Mvc.Core;
|
using Microsoft.AspNet.Mvc.Core;
|
||||||
|
|
@ -31,19 +30,13 @@ namespace Microsoft.AspNet.Mvc
|
||||||
/// <param name="include">Names of parameters to include in binding.</param>
|
/// <param name="include">Names of parameters to include in binding.</param>
|
||||||
public BindAttribute(params string[] include)
|
public BindAttribute(params string[] include)
|
||||||
{
|
{
|
||||||
var items = new List<string>();
|
Include = include;
|
||||||
foreach (var item in include)
|
|
||||||
{
|
|
||||||
items.AddRange(SplitString(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
Include = items.ToArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of <see cref="BindAttribute"/>.
|
/// Creates a new instance of <see cref="BindAttribute"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="predicateProviderType">The type which implements
|
/// <param name="predicateProviderType">The type which implements
|
||||||
/// <see cref="IPropertyBindingPredicateProvider"/>.
|
/// <see cref="IPropertyBindingPredicateProvider"/>.
|
||||||
/// </param>
|
/// </param>
|
||||||
public BindAttribute([NotNull] Type predicateProviderType)
|
public BindAttribute([NotNull] Type predicateProviderType)
|
||||||
|
|
@ -99,7 +92,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
if (_predicateFromInclude == null)
|
if (_predicateFromInclude == null)
|
||||||
{
|
{
|
||||||
_predicateFromInclude =
|
_predicateFromInclude =
|
||||||
(context, propertyName) => Include.Contains(propertyName, StringComparer.Ordinal);
|
(context, propertyName) => Include.Contains(propertyName, StringComparer.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,17 +136,5 @@ namespace Microsoft.AspNet.Mvc
|
||||||
return predicate(context, propertyName);
|
return predicate(context, propertyName);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<string> SplitString(string original)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(original))
|
|
||||||
{
|
|
||||||
return new string[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
var split = original.Split(',').Select(piece => piece.Trim()).Where(piece => !string.IsNullOrEmpty(piece));
|
|
||||||
|
|
||||||
return split;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,15 +44,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
[InlineData("UserName", true)]
|
[InlineData("UserName", true)]
|
||||||
[InlineData("Username", false)]
|
[InlineData("Username", false)]
|
||||||
[InlineData("Password", false)]
|
[InlineData("Password", false)]
|
||||||
[InlineData("LastName", true)]
|
|
||||||
[InlineData("MiddleName", true)]
|
|
||||||
[InlineData(" ", false)]
|
|
||||||
[InlineData("foo", true)]
|
|
||||||
[InlineData("bar", true)]
|
|
||||||
public void BindAttribute_Include(string property, bool isIncluded)
|
public void BindAttribute_Include(string property, bool isIncluded)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var bind = new BindAttribute(new string[] { "UserName", "FirstName", "LastName, MiddleName, ,foo,bar " });
|
var bind = new BindAttribute(new string[] { "UserName", "FirstName" });
|
||||||
|
|
||||||
var context = new ModelBindingContext();
|
var context = new ModelBindingContext();
|
||||||
|
|
||||||
|
|
@ -79,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
HttpContext = new DefaultHttpContext(),
|
HttpContext = new DefaultHttpContext(),
|
||||||
};
|
};
|
||||||
var services = new Mock<IServiceProvider>();
|
var services = new Mock<IServiceProvider>();
|
||||||
|
|
||||||
context.OperationBindingContext.HttpContext.RequestServices = services.Object;
|
context.OperationBindingContext.HttpContext.RequestServices = services.Object;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -104,7 +99,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||||
};
|
};
|
||||||
|
|
||||||
var services = new Mock<IServiceProvider>(MockBehavior.Strict);
|
var services = new Mock<IServiceProvider>(MockBehavior.Strict);
|
||||||
|
|
||||||
context.OperationBindingContext.HttpContext.RequestServices = services.Object;
|
context.OperationBindingContext.HttpContext.RequestServices = services.Object;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue