diff --git a/src/Microsoft.AspNet.Routing/Constraints/LengthRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/LengthRouteConstraint.cs index c9e8c2a3be..e449dff7d2 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/LengthRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/LengthRouteConstraint.cs @@ -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; diff --git a/src/Microsoft.AspNet.Routing/Constraints/MaxLengthRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/MaxLengthRouteConstraint.cs index b471669e6c..4249b6a4f1 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/MaxLengthRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/MaxLengthRouteConstraint.cs @@ -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; diff --git a/src/Microsoft.AspNet.Routing/Constraints/MinLengthRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/MinLengthRouteConstraint.cs index 6aa7915346..da4996b5aa 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/MinLengthRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/MinLengthRouteConstraint.cs @@ -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; diff --git a/src/Microsoft.AspNet.Routing/Constraints/RangeRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/RangeRouteConstraint.cs index b1f7b40c48..fe080ab687 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/RangeRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/RangeRouteConstraint.cs @@ -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; diff --git a/src/Microsoft.AspNet.Routing/RouteContext.cs b/src/Microsoft.AspNet.Routing/RouteContext.cs index bace7fbfeb..d658c67f70 100644 --- a/src/Microsoft.AspNet.Routing/RouteContext.cs +++ b/src/Microsoft.AspNet.Routing/RouteContext.cs @@ -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; } } diff --git a/src/Microsoft.AspNet.Routing/RouteOptions.cs b/src/Microsoft.AspNet.Routing/RouteOptions.cs index a678a3ffe4..4bcb1d556b 100644 --- a/src/Microsoft.AspNet.Routing/RouteOptions.cs +++ b/src/Microsoft.AspNet.Routing/RouteOptions.cs @@ -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; } } diff --git a/src/Microsoft.AspNet.Routing/Template/RouteTemplate.cs b/src/Microsoft.AspNet.Routing/Template/RouteTemplate.cs index 46d0cdcf41..057e5b89d8 100644 --- a/src/Microsoft.AspNet.Routing/Template/RouteTemplate.cs +++ b/src/Microsoft.AspNet.Routing/Template/RouteTemplate.cs @@ -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 segments) + public RouteTemplate([NotNull] List segments) { - if (segments == null) - { - throw new ArgumentNullException("segments"); - } - Segments = segments; Parameters = new List(); diff --git a/src/Microsoft.AspNet.Routing/Template/TemplateBinder.cs b/src/Microsoft.AspNet.Routing/Template/TemplateBinder.cs index 779496f9a2..749291d753 100644 --- a/src/Microsoft.AspNet.Routing/Template/TemplateBinder.cs +++ b/src/Microsoft.AspNet.Routing/Template/TemplateBinder.cs @@ -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 _defaults; private readonly RouteTemplate _template; - public TemplateBinder(RouteTemplate template, IReadOnlyDictionary defaults) + public TemplateBinder([NotNull] RouteTemplate template, IReadOnlyDictionary defaults) { - if (template == null) - { - throw new ArgumentNullException("template"); - } - _template = template; _defaults = defaults; } @@ -357,13 +353,8 @@ namespace Microsoft.AspNet.Routing.Template public TemplateBindingContext( IReadOnlyDictionary defaults, - IDictionary values) + [NotNull] IDictionary values) { - if (values == null) - { - throw new ArgumentNullException("values"); - } - _defaults = defaults; _acceptedValues = new RouteValueDictionary(); diff --git a/src/Microsoft.AspNet.Routing/Template/TemplateParser.cs b/src/Microsoft.AspNet.Routing/Template/TemplateParser.cs index 95997cec3b..9ef04663b2 100644 --- a/src/Microsoft.AspNet.Routing/Template/TemplateParser.cs +++ b/src/Microsoft.AspNet.Routing/Template/TemplateParser.cs @@ -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)); } }