From 5b0b0b95a7d6d40c4506abb105186042934a9b4b Mon Sep 17 00:00:00 2001 From: Caleb Nelton Date: Wed, 17 Feb 2016 09:59:41 -0600 Subject: [PATCH] Small Refactorings Use nameof Replace with single call to SingleOrDefault Replace with single call to FirstOrDefault Simplify conditionals --- .../ModelBinding/BindingSource.cs | 2 +- .../ModelBinding/ValueProviderResult.cs | 2 +- src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRoute.cs | 3 +-- .../Internal/DefaultApplicationModelProvider.cs | 3 +-- .../ModelBinding/JQueryFormValueProviderFactory.cs | 4 ++-- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/BindingSource.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/BindingSource.cs index 8c5aa047d8..ce93735339 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/BindingSource.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/BindingSource.cs @@ -183,7 +183,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// public bool Equals(BindingSource other) { - return other == null ? false : string.Equals(other.Id, Id, StringComparison.Ordinal); + return string.Equals(other?.Id, Id, StringComparison.Ordinal); } /// diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ValueProviderResult.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ValueProviderResult.cs index 24eb847fde..d0e3d206b7 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ValueProviderResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/ModelBinding/ValueProviderResult.cs @@ -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); } /// diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRoute.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRoute.cs index 641ac90ac0..5b94ffb36d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRoute.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRoute.cs @@ -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) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs index d3785b00d0..9099575073 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs @@ -592,8 +592,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var routeTemplateProvider = attributes .OfType() - .Where(a => !IsSilentRouteAttribute(a)) - .SingleOrDefault(); + .SingleOrDefault(a => !IsSilentRouteAttribute(a)); if (routeTemplateProvider != null) { diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/JQueryFormValueProviderFactory.cs b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/JQueryFormValueProviderFactory.cs index 4d4af8b13f..e036205311 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/JQueryFormValueProviderFactory.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/JQueryFormValueProviderFactory.cs @@ -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)