From 92554fa634b9feea1c3ad6688e83c598f8875aca Mon Sep 17 00:00:00 2001 From: Henk Mollema Date: Tue, 21 Apr 2015 17:32:58 +0200 Subject: [PATCH] Utilize `nameof` operator --- .../ActionResults/RedirectResult.cs | 4 ++-- .../AntiForgery/AntiForgeryTokenSet.cs | 2 +- src/Microsoft.AspNet.Mvc.Core/Areas/AreaAttribute.cs | 2 +- src/Microsoft.AspNet.Mvc.Core/Controller.cs | 4 ++-- src/Microsoft.AspNet.Mvc.Core/FormatterMappings.cs | 2 +- src/Microsoft.AspNet.Mvc.Core/RemoteAttribute.cs | 4 ++-- .../Rendering/Html/TagBuilder.cs | 4 ++-- .../Rendering/UnobtrusiveValidationAttributesGenerator.cs | 2 +- src/Microsoft.AspNet.Mvc.Core/RouteConstraintAttribute.cs | 2 +- .../Routing/InnerAttributeRoute.cs | 2 +- .../BinderMetadata/CompositeBindingSource.cs | 6 +++--- .../Internal/ModelBindingHelper.cs | 8 ++++---- .../Validation/DataTypeAttributeAdapter.cs | 2 +- .../Directives/ChunkHelper.cs | 2 +- .../FormDataCollectionExtensions.cs | 2 +- 15 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResults/RedirectResult.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResults/RedirectResult.cs index 36d9b9b109..0b37596c44 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ActionResults/RedirectResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ActionResults/RedirectResult.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Mvc { if (string.IsNullOrEmpty(url)) { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "url"); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(url)); } Permanent = permanent; @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Mvc { if (string.IsNullOrEmpty(value)) { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "value"); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(value)); } _url = value; diff --git a/src/Microsoft.AspNet.Mvc.Core/AntiForgery/AntiForgeryTokenSet.cs b/src/Microsoft.AspNet.Mvc.Core/AntiForgery/AntiForgeryTokenSet.cs index e3158ffdc2..23feebbf7f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/AntiForgery/AntiForgeryTokenSet.cs +++ b/src/Microsoft.AspNet.Mvc.Core/AntiForgery/AntiForgeryTokenSet.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Mvc { if (string.IsNullOrEmpty(formToken)) { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, formToken); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(formToken)); } FormToken = formToken; diff --git a/src/Microsoft.AspNet.Mvc.Core/Areas/AreaAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/Areas/AreaAttribute.cs index 43ad126c10..d8ea189e48 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Areas/AreaAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Areas/AreaAttribute.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc { if (string.IsNullOrEmpty(areaName)) { - throw new ArgumentException("Area name must not be empty", "areaName"); + throw new ArgumentException("Area name must not be empty", nameof(areaName)); } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Controller.cs b/src/Microsoft.AspNet.Mvc.Core/Controller.cs index 56dd9bec9d..165f818051 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controller.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controller.cs @@ -396,7 +396,7 @@ namespace Microsoft.AspNet.Mvc { if (string.IsNullOrEmpty(url)) { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "url"); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(url)); } return new RedirectResult(url); @@ -413,7 +413,7 @@ namespace Microsoft.AspNet.Mvc { if (string.IsNullOrEmpty(url)) { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "url"); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(url)); } return new RedirectResult(url, permanent: true); diff --git a/src/Microsoft.AspNet.Mvc.Core/FormatterMappings.cs b/src/Microsoft.AspNet.Mvc.Core/FormatterMappings.cs index 4118455d83..ab184bd690 100644 --- a/src/Microsoft.AspNet.Mvc.Core/FormatterMappings.cs +++ b/src/Microsoft.AspNet.Mvc.Core/FormatterMappings.cs @@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Mvc { if (format == "") { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "format"); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(format)); } if (format.StartsWith(".")) diff --git a/src/Microsoft.AspNet.Mvc.Core/RemoteAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/RemoteAttribute.cs index 5de4ed2630..fbde51c968 100644 --- a/src/Microsoft.AspNet.Mvc.Core/RemoteAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/RemoteAttribute.cs @@ -156,7 +156,7 @@ namespace Microsoft.AspNet.Mvc { if (string.IsNullOrEmpty(property)) { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "property"); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(property)); } var delimitedAdditionalFields = string.Join(",", _additionalFieldsSplit); @@ -180,7 +180,7 @@ namespace Microsoft.AspNet.Mvc { if (string.IsNullOrEmpty(property)) { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "property"); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(property)); } return "*." + property; diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/TagBuilder.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/TagBuilder.cs index f9b9aa352a..8ca33d0dfc 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/TagBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/TagBuilder.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.Rendering { if (string.IsNullOrEmpty(tagName)) { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "tagName"); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(tagName)); } TagName = tagName; @@ -142,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.Rendering { if (string.IsNullOrEmpty(key)) { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "key"); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(key)); } if (replaceExisting || !Attributes.ContainsKey(key)) diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/UnobtrusiveValidationAttributesGenerator.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/UnobtrusiveValidationAttributesGenerator.cs index a2d769cf00..6f579f0767 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/UnobtrusiveValidationAttributesGenerator.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/UnobtrusiveValidationAttributesGenerator.cs @@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Mvc.Rendering { throw new ArgumentException( Resources.FormatUnobtrusiveJavascript_ValidationTypeCannotBeEmpty(rule.GetType().FullName), - "rule"); + nameof(rule)); } if (resultsDictionary.ContainsKey(dictionaryKey)) diff --git a/src/Microsoft.AspNet.Mvc.Core/RouteConstraintAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/RouteConstraintAttribute.cs index 781a34d427..51b9d793b2 100644 --- a/src/Microsoft.AspNet.Mvc.Core/RouteConstraintAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/RouteConstraintAttribute.cs @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Mvc var message = Resources.FormatRouteConstraintAttribute_InvalidKeyHandlingValue( Enum.GetName(typeof(RouteKeyHandling), RouteKeyHandling.CatchAll), Enum.GetName(typeof(RouteKeyHandling), RouteKeyHandling.DenyKey)); - throw new ArgumentException(message, "keyHandling"); + throw new ArgumentException(message, nameof(keyHandling)); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Routing/InnerAttributeRoute.cs b/src/Microsoft.AspNet.Mvc.Core/Routing/InnerAttributeRoute.cs index 0bcc10d827..8524844b17 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Routing/InnerAttributeRoute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Routing/InnerAttributeRoute.cs @@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Mvc.Routing { throw new ArgumentException( Resources.FormatAttributeRoute_DifferentLinkGenerationEntries_SameName(entry.Name), - "linkGenerationEntries"); + nameof(linkGenerationEntries)); } else if (namedEntry == null) { diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/BinderMetadata/CompositeBindingSource.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/BinderMetadata/CompositeBindingSource.cs index 98b47748aa..b9414c91cc 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/BinderMetadata/CompositeBindingSource.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/BinderMetadata/CompositeBindingSource.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var message = Resources.FormatBindingSource_CannotBeGreedy( bindingSource.DisplayName, nameof(CompositeBindingSource)); - throw new ArgumentException(message, "bindingSources"); + throw new ArgumentException(message, nameof(bindingSources)); } if (!bindingSource.IsFromRequest) @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var message = Resources.FormatBindingSource_MustBeFromRequest( bindingSource.DisplayName, nameof(CompositeBindingSource)); - throw new ArgumentException(message, "bindingSources"); + throw new ArgumentException(message, nameof(bindingSources)); } if (bindingSource is CompositeBindingSource) @@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding var message = Resources.FormatBindingSource_CannotBeComposite( bindingSource.DisplayName, nameof(CompositeBindingSource)); - throw new ArgumentException(message, "bindingSources"); + throw new ArgumentException(message, nameof(bindingSources)); } } diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/ModelBindingHelper.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/ModelBindingHelper.cs index 6419c71727..ebbd3ff221 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/ModelBindingHelper.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Internal/ModelBindingHelper.cs @@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Internal { if (bindingContext.ModelMetadata == null) { - throw new ArgumentException(Resources.ModelBinderUtil_ModelMetadataCannotBeNull, "bindingContext"); + throw new ArgumentException(Resources.ModelBinderUtil_ModelMetadataCannotBeNull, nameof(bindingContext)); } } @@ -78,13 +78,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Internal if (bindingContext.ModelType != requiredType) { var message = Resources.FormatModelBinderUtil_ModelTypeIsWrong(bindingContext.ModelType, requiredType); - throw new ArgumentException(message, "bindingContext"); + throw new ArgumentException(message, nameof(bindingContext)); } if (!allowNullModel && bindingContext.Model == null) { var message = Resources.FormatModelBinderUtil_ModelCannotBeNull(requiredType); - throw new ArgumentException(message, "bindingContext"); + throw new ArgumentException(message, nameof(bindingContext)); } if (bindingContext.Model != null && @@ -93,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Internal var message = Resources.FormatModelBinderUtil_ModelInstanceIsWrong( bindingContext.Model.GetType(), requiredType); - throw new ArgumentException(message, "bindingContext"); + throw new ArgumentException(message, nameof(bindingContext)); } } diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataTypeAttributeAdapter.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataTypeAttributeAdapter.cs index a28bc4cc00..4bdf7729cb 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataTypeAttributeAdapter.cs +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Validation/DataTypeAttributeAdapter.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation { if (string.IsNullOrEmpty(ruleName)) { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "ruleName"); + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(ruleName)); } RuleName = ruleName; } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs index 7d365fe02c..48a26f5cf5 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/ChunkHelper.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives if (chunkOfT == null) { var message = Resources.FormatArgumentMustBeOfType(typeof(TChunk).FullName); - throw new ArgumentException(message, "chunk"); + throw new ArgumentException(message, nameof(chunk)); } return chunkOfT; diff --git a/src/Microsoft.AspNet.Mvc.WebApiCompatShim/FormDataCollectionExtensions.cs b/src/Microsoft.AspNet.Mvc.WebApiCompatShim/FormDataCollectionExtensions.cs index 9575783507..dc54ebdae4 100644 --- a/src/Microsoft.AspNet.Mvc.WebApiCompatShim/FormDataCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.WebApiCompatShim/FormDataCollectionExtensions.cs @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim var indexClose = key.IndexOf(']', indexOpen); if (indexClose == -1) { - throw new ArgumentException(Resources.JQuerySyntaxMissingClosingBracket, "key"); + throw new ArgumentException(Resources.JQuerySyntaxMissingClosingBracket, nameof(key)); } if (indexClose == indexOpen + 1)