Using [NotNull] and 'nameof' operator

This commit is contained in:
Hisham Abdullah Bin Ateya 2015-05-06 17:43:19 +03:00
parent f2e6c294b0
commit 8636477b85
9 changed files with 20 additions and 41 deletions

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Routing.Constraints
if (length < 0)
{
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
throw new ArgumentOutOfRangeException("length", length, errorMessage);
throw new ArgumentOutOfRangeException(nameof(length), length, errorMessage);
}
MinLength = MaxLength = length;
@ -41,20 +41,20 @@ namespace Microsoft.AspNet.Routing.Constraints
if (minLength < 0)
{
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
throw new ArgumentOutOfRangeException("minLength", minLength, errorMessage);
throw new ArgumentOutOfRangeException(nameof(minLength), minLength, errorMessage);
}
if (maxLength < 0)
{
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
throw new ArgumentOutOfRangeException("maxLength", maxLength, errorMessage);
throw new ArgumentOutOfRangeException(nameof(maxLength), maxLength, errorMessage);
}
if (minLength > maxLength)
{
var errorMessage =
Resources.FormatRangeConstraint_MinShouldBeLessThanOrEqualToMax("minLength", "maxLength");
throw new ArgumentOutOfRangeException("minLength", minLength, errorMessage);
throw new ArgumentOutOfRangeException(nameof(minLength), minLength, errorMessage);
}
MinLength = minLength;

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Routing.Constraints
if (maxLength < 0)
{
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
throw new ArgumentOutOfRangeException("maxLength", maxLength, errorMessage);
throw new ArgumentOutOfRangeException(nameof(maxLength), maxLength, errorMessage);
}
MaxLength = maxLength;

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Routing.Constraints
if (minLength < 0)
{
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
throw new ArgumentOutOfRangeException("minLength", minLength, errorMessage);
throw new ArgumentOutOfRangeException(nameof(minLength), minLength, errorMessage);
}
MinLength = minLength;

View File

@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Routing.Constraints
if (min > max)
{
var errorMessage = Resources.FormatRangeConstraint_MinShouldBeLessThanOrEqualToMax("min", "max");
throw new ArgumentOutOfRangeException("min", min, errorMessage);
throw new ArgumentOutOfRangeException(nameof(min), min, errorMessage);
}
Min = min;

View File

@ -3,6 +3,7 @@
using System;
using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing
{
@ -27,13 +28,9 @@ namespace Microsoft.AspNet.Routing
{
return _routeData;
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
_routeData = value;
}
}

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Routing.Constraints;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing
{
@ -22,15 +23,9 @@ namespace Microsoft.AspNet.Routing
{
return _constraintTypeMap;
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException("value",
Resources.FormatPropertyOfTypeCannotBeNull(
"ConstraintMap", typeof(RouteOptions)));
}
_constraintTypeMap = value;
}
}

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Template
{
@ -13,13 +14,8 @@ namespace Microsoft.AspNet.Routing.Template
{
private const string SeparatorString = "/";
public RouteTemplate(List<TemplateSegment> segments)
public RouteTemplate([NotNull] List<TemplateSegment> segments)
{
if (segments == null)
{
throw new ArgumentNullException("segments");
}
Segments = segments;
Parameters = new List<TemplatePart>();

View File

@ -8,6 +8,7 @@ using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.AspNet.Http.Extensions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Template
{
@ -16,13 +17,8 @@ namespace Microsoft.AspNet.Routing.Template
private readonly IReadOnlyDictionary<string, object> _defaults;
private readonly RouteTemplate _template;
public TemplateBinder(RouteTemplate template, IReadOnlyDictionary<string, object> defaults)
public TemplateBinder([NotNull] RouteTemplate template, IReadOnlyDictionary<string, object> defaults)
{
if (template == null)
{
throw new ArgumentNullException("template");
}
_template = template;
_defaults = defaults;
}
@ -357,13 +353,8 @@ namespace Microsoft.AspNet.Routing.Template
public TemplateBindingContext(
IReadOnlyDictionary<string, object> defaults,
IDictionary<string, object> values)
[NotNull] IDictionary<string, object> values)
{
if (values == null)
{
throw new ArgumentNullException("values");
}
_defaults = defaults;
_acceptedValues = new RouteValueDictionary();

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Routing.Template
if (IsInvalidRouteTemplate(routeTemplate))
{
throw new ArgumentException(Resources.TemplateRoute_InvalidRouteTemplate, "routeTemplate");
throw new ArgumentException(Resources.TemplateRoute_InvalidRouteTemplate, nameof(routeTemplate));
}
var context = new TemplateParserContext(routeTemplate);
@ -41,13 +41,13 @@ namespace Microsoft.AspNet.Routing.Template
// If we get here is means that there's a consecutive '/' character.
// Templates don't start with a '/' and parsing a segment consumes the separator.
throw new ArgumentException(Resources.TemplateRoute_CannotHaveConsecutiveSeparators,
"routeTemplate");
nameof(routeTemplate));
}
else
{
if (!ParseSegment(context, segments))
{
throw new ArgumentException(context.Error, "routeTemplate");
throw new ArgumentException(context.Error, nameof(routeTemplate));
}
}
}
@ -58,7 +58,7 @@ namespace Microsoft.AspNet.Routing.Template
}
else
{
throw new ArgumentException(context.Error, "routeTemplate");
throw new ArgumentException(context.Error, nameof(routeTemplate));
}
}