Small Refactorings

Use nameof
Replace with single call to SingleOrDefault
Replace with single call to FirstOrDefault
Simplify conditionals
This commit is contained in:
Caleb Nelton 2016-02-17 09:59:41 -06:00 committed by Pranav K
parent 80b6996701
commit 5b0b0b95a7
5 changed files with 6 additions and 8 deletions

View File

@ -183,7 +183,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// <inheritdoc />
public bool Equals(BindingSource other)
{
return other == null ? false : string.Equals(other.Id, Id, StringComparison.Ordinal);
return string.Equals(other?.Id, Id, StringComparison.Ordinal);
}
/// <inheritdoc />

View File

@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
public override bool Equals(object obj)
{
var other = obj as ValueProviderResult?;
return other.HasValue ? Equals(other.Value) : false;
return other.HasValue && Equals(other.Value);
}
/// <inheritdoc />

View File

@ -220,8 +220,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
ActionDescriptor action)
{
var constraint = action.RouteConstraints
.Where(c => c.RouteKey == TreeRouter.RouteGroupKey)
.FirstOrDefault();
.FirstOrDefault(c => c.RouteKey == TreeRouter.RouteGroupKey);
if (constraint == null ||
constraint.KeyHandling != RouteKeyHandling.RequireKey ||
constraint.RouteValue == null)

View File

@ -592,8 +592,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
var routeTemplateProvider =
attributes
.OfType<IRouteTemplateProvider>()
.Where(a => !IsSilentRouteAttribute(a))
.SingleOrDefault();
.SingleOrDefault(a => !IsSilentRouteAttribute(a));
if (routeTemplateProvider != null)
{

View File

@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
throw new ArgumentNullException(nameof(context));
}
var request = context.ActionContext.HttpContext.Request;
if (request.HasFormContentType)
{
@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
{
throw new ArgumentException(
message: Resources.FormatJQueryFormValueProviderFactory_MissingClosingBracket(key),
paramName: "key");
paramName: nameof(key));
}
if (indexClose == indexOpen + 1)