Utilize `nameof` operator

This commit is contained in:
Henk Mollema 2015-04-21 17:32:58 +02:00 committed by Kiran Challa
parent 7b7667e338
commit 92554fa634
15 changed files with 24 additions and 24 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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));
}
}
}

View File

@ -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);

View File

@ -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("."))

View File

@ -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;

View File

@ -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))

View File

@ -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))

View File

@ -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));
}
}

View File

@ -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)
{

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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)