Using [NotNull] and 'nameof' operator
This commit is contained in:
parent
f2e6c294b0
commit
8636477b85
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Routing.Constraints
|
||||||
if (length < 0)
|
if (length < 0)
|
||||||
{
|
{
|
||||||
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
|
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
|
||||||
throw new ArgumentOutOfRangeException("length", length, errorMessage);
|
throw new ArgumentOutOfRangeException(nameof(length), length, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
MinLength = MaxLength = length;
|
MinLength = MaxLength = length;
|
||||||
|
|
@ -41,20 +41,20 @@ namespace Microsoft.AspNet.Routing.Constraints
|
||||||
if (minLength < 0)
|
if (minLength < 0)
|
||||||
{
|
{
|
||||||
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
|
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
|
||||||
throw new ArgumentOutOfRangeException("minLength", minLength, errorMessage);
|
throw new ArgumentOutOfRangeException(nameof(minLength), minLength, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxLength < 0)
|
if (maxLength < 0)
|
||||||
{
|
{
|
||||||
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
|
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
|
||||||
throw new ArgumentOutOfRangeException("maxLength", maxLength, errorMessage);
|
throw new ArgumentOutOfRangeException(nameof(maxLength), maxLength, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minLength > maxLength)
|
if (minLength > maxLength)
|
||||||
{
|
{
|
||||||
var errorMessage =
|
var errorMessage =
|
||||||
Resources.FormatRangeConstraint_MinShouldBeLessThanOrEqualToMax("minLength", "maxLength");
|
Resources.FormatRangeConstraint_MinShouldBeLessThanOrEqualToMax("minLength", "maxLength");
|
||||||
throw new ArgumentOutOfRangeException("minLength", minLength, errorMessage);
|
throw new ArgumentOutOfRangeException(nameof(minLength), minLength, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
MinLength = minLength;
|
MinLength = minLength;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Routing.Constraints
|
||||||
if (maxLength < 0)
|
if (maxLength < 0)
|
||||||
{
|
{
|
||||||
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
|
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
|
||||||
throw new ArgumentOutOfRangeException("maxLength", maxLength, errorMessage);
|
throw new ArgumentOutOfRangeException(nameof(maxLength), maxLength, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
MaxLength = maxLength;
|
MaxLength = maxLength;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Routing.Constraints
|
||||||
if (minLength < 0)
|
if (minLength < 0)
|
||||||
{
|
{
|
||||||
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
|
var errorMessage = Resources.FormatArgumentMustBeGreaterThanOrEqualTo(0);
|
||||||
throw new ArgumentOutOfRangeException("minLength", minLength, errorMessage);
|
throw new ArgumentOutOfRangeException(nameof(minLength), minLength, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
MinLength = minLength;
|
MinLength = minLength;
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Routing.Constraints
|
||||||
if (min > max)
|
if (min > max)
|
||||||
{
|
{
|
||||||
var errorMessage = Resources.FormatRangeConstraint_MinShouldBeLessThanOrEqualToMax("min", "max");
|
var errorMessage = Resources.FormatRangeConstraint_MinShouldBeLessThanOrEqualToMax("min", "max");
|
||||||
throw new ArgumentOutOfRangeException("min", min, errorMessage);
|
throw new ArgumentOutOfRangeException(nameof(min), min, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
Min = min;
|
Min = min;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
using Microsoft.Framework.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Routing
|
namespace Microsoft.AspNet.Routing
|
||||||
{
|
{
|
||||||
|
|
@ -27,13 +28,9 @@ namespace Microsoft.AspNet.Routing
|
||||||
{
|
{
|
||||||
return _routeData;
|
return _routeData;
|
||||||
}
|
}
|
||||||
|
[param: NotNull]
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("value");
|
|
||||||
}
|
|
||||||
|
|
||||||
_routeData = value;
|
_routeData = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNet.Routing.Constraints;
|
using Microsoft.AspNet.Routing.Constraints;
|
||||||
|
using Microsoft.Framework.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Routing
|
namespace Microsoft.AspNet.Routing
|
||||||
{
|
{
|
||||||
|
|
@ -22,15 +23,9 @@ namespace Microsoft.AspNet.Routing
|
||||||
{
|
{
|
||||||
return _constraintTypeMap;
|
return _constraintTypeMap;
|
||||||
}
|
}
|
||||||
|
[param: NotNull]
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("value",
|
|
||||||
Resources.FormatPropertyOfTypeCannotBeNull(
|
|
||||||
"ConstraintMap", typeof(RouteOptions)));
|
|
||||||
}
|
|
||||||
|
|
||||||
_constraintTypeMap = value;
|
_constraintTypeMap = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.Framework.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Routing.Template
|
namespace Microsoft.AspNet.Routing.Template
|
||||||
{
|
{
|
||||||
|
|
@ -13,13 +14,8 @@ namespace Microsoft.AspNet.Routing.Template
|
||||||
{
|
{
|
||||||
private const string SeparatorString = "/";
|
private const string SeparatorString = "/";
|
||||||
|
|
||||||
public RouteTemplate(List<TemplateSegment> segments)
|
public RouteTemplate([NotNull] List<TemplateSegment> segments)
|
||||||
{
|
{
|
||||||
if (segments == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("segments");
|
|
||||||
}
|
|
||||||
|
|
||||||
Segments = segments;
|
Segments = segments;
|
||||||
|
|
||||||
Parameters = new List<TemplatePart>();
|
Parameters = new List<TemplatePart>();
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.AspNet.Http.Extensions;
|
using Microsoft.AspNet.Http.Extensions;
|
||||||
|
using Microsoft.Framework.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Routing.Template
|
namespace Microsoft.AspNet.Routing.Template
|
||||||
{
|
{
|
||||||
|
|
@ -16,13 +17,8 @@ namespace Microsoft.AspNet.Routing.Template
|
||||||
private readonly IReadOnlyDictionary<string, object> _defaults;
|
private readonly IReadOnlyDictionary<string, object> _defaults;
|
||||||
private readonly RouteTemplate _template;
|
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;
|
_template = template;
|
||||||
_defaults = defaults;
|
_defaults = defaults;
|
||||||
}
|
}
|
||||||
|
|
@ -357,13 +353,8 @@ namespace Microsoft.AspNet.Routing.Template
|
||||||
|
|
||||||
public TemplateBindingContext(
|
public TemplateBindingContext(
|
||||||
IReadOnlyDictionary<string, object> defaults,
|
IReadOnlyDictionary<string, object> defaults,
|
||||||
IDictionary<string, object> values)
|
[NotNull] IDictionary<string, object> values)
|
||||||
{
|
{
|
||||||
if (values == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("values");
|
|
||||||
}
|
|
||||||
|
|
||||||
_defaults = defaults;
|
_defaults = defaults;
|
||||||
|
|
||||||
_acceptedValues = new RouteValueDictionary();
|
_acceptedValues = new RouteValueDictionary();
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Routing.Template
|
||||||
|
|
||||||
if (IsInvalidRouteTemplate(routeTemplate))
|
if (IsInvalidRouteTemplate(routeTemplate))
|
||||||
{
|
{
|
||||||
throw new ArgumentException(Resources.TemplateRoute_InvalidRouteTemplate, "routeTemplate");
|
throw new ArgumentException(Resources.TemplateRoute_InvalidRouteTemplate, nameof(routeTemplate));
|
||||||
}
|
}
|
||||||
|
|
||||||
var context = new TemplateParserContext(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.
|
// 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.
|
// Templates don't start with a '/' and parsing a segment consumes the separator.
|
||||||
throw new ArgumentException(Resources.TemplateRoute_CannotHaveConsecutiveSeparators,
|
throw new ArgumentException(Resources.TemplateRoute_CannotHaveConsecutiveSeparators,
|
||||||
"routeTemplate");
|
nameof(routeTemplate));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!ParseSegment(context, segments))
|
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
|
else
|
||||||
{
|
{
|
||||||
throw new ArgumentException(context.Error, "routeTemplate");
|
throw new ArgumentException(context.Error, nameof(routeTemplate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue