From c6941e797f1585730b69d088a3b1b0c17ce6afa7 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 10 Sep 2015 22:16:45 -0700 Subject: [PATCH] Replacing NotNullAttribute with exceptions --- .../BuilderExtensions.cs | 14 ++++- .../Constraints/BoolRouteConstraint.cs | 32 +++++++++-- .../Constraints/CompositeRouteConstraint.cs | 40 ++++++++++--- .../Constraints/DateTimeRouteConstraint.cs | 32 +++++++++-- .../Constraints/DecimalRouteConstraint.cs | 32 +++++++++-- .../Constraints/DoubleRouteConstraint.cs | 32 +++++++++-- .../Constraints/FloatRouteConstraint.cs | 32 +++++++++-- .../Constraints/GuidRouteConstraint.cs | 32 +++++++++-- .../Constraints/IntRouteConstraint.cs | 32 +++++++++-- .../Constraints/LengthRouteConstraint.cs | 32 +++++++++-- .../Constraints/LongRouteConstraint.cs | 34 ++++++++--- .../Constraints/MaxLengthRouteConstraint.cs | 32 +++++++++-- .../Constraints/MaxRouteConstraint.cs | 32 +++++++++-- .../Constraints/MinLengthRouteConstraint.cs | 32 +++++++++-- .../Constraints/MinRouteConstraint.cs | 32 +++++++++-- .../Constraints/OptionalRouteConstraint.cs | 40 ++++++++++--- .../Constraints/RangeRouteConstraint.cs | 32 +++++++++-- .../Constraints/RegexInlineRouteConstraint.cs | 4 +- .../Constraints/RegexRouteConstraint.cs | 46 ++++++++++++--- .../Constraints/RequiredRouteConstraint.cs | 29 ++++++++-- .../DefaultInlineConstraintResolver.cs | 8 ++- .../IInlineConstraintResolver.cs | 4 +- .../IRouteConstraint.cs | 9 ++- .../InlineRouteParameterParser.cs | 9 ++- .../Logging/LoggerExtensions.cs | 9 ++- .../RouteCollection.cs | 8 ++- .../RouteConstraintBuilder.cs | 48 +++++++++++++--- .../RouteConstraintMatcher.cs | 32 +++++++++-- src/Microsoft.AspNet.Routing/RouteContext.cs | 7 ++- src/Microsoft.AspNet.Routing/RouteData.cs | 8 ++- src/Microsoft.AspNet.Routing/RouteOptions.cs | 7 ++- .../RouteValueDictionary.cs | 48 +++++++++++++--- .../ServiceCollectionExtensions.cs | 8 ++- .../Template/InlineConstraint.cs | 9 ++- .../Template/RouteTemplate.cs | 8 ++- .../Template/TemplateBinder.cs | 17 ++++-- .../Template/TemplateMatcher.cs | 34 +++++++---- .../Template/TemplatePart.cs | 9 ++- .../Template/TemplateRoute.cs | 56 +++++++++++-------- .../VirtualPathData.cs | 15 +++-- src/Microsoft.AspNet.Routing/project.json | 6 +- .../Template/TemplateMatcherTests.cs | 8 +-- 42 files changed, 772 insertions(+), 218 deletions(-) diff --git a/src/Microsoft.AspNet.Routing/BuilderExtensions.cs b/src/Microsoft.AspNet.Routing/BuilderExtensions.cs index dc2aa0d0ab..ebc409f128 100644 --- a/src/Microsoft.AspNet.Routing/BuilderExtensions.cs +++ b/src/Microsoft.AspNet.Routing/BuilderExtensions.cs @@ -1,15 +1,25 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNet.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Builder { public static class BuilderExtensions { - public static IApplicationBuilder UseRouter([NotNull] this IApplicationBuilder builder, [NotNull] IRouter router) + public static IApplicationBuilder UseRouter(this IApplicationBuilder builder, IRouter router) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (router == null) + { + throw new ArgumentNullException(nameof(router)); + } + return builder.UseMiddleware(router); } } diff --git a/src/Microsoft.AspNet.Routing/Constraints/BoolRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/BoolRouteConstraint.cs index 39247d03ca..8c603bf9c3 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/BoolRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/BoolRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints public class BoolRouteConstraint : IRouteConstraint { /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/CompositeRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/CompositeRouteConstraint.cs index 182a285070..4ba46b4eeb 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/CompositeRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/CompositeRouteConstraint.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing { @@ -16,8 +16,13 @@ namespace Microsoft.AspNet.Routing /// Initializes a new instance of the class. /// /// The child constraints that must match for this constraint to match. - public CompositeRouteConstraint([NotNull] IEnumerable constraints) + public CompositeRouteConstraint(IEnumerable constraints) { + if (constraints == null) + { + throw new ArgumentNullException(nameof(constraints)); + } + Constraints = constraints; } @@ -27,12 +32,33 @@ namespace Microsoft.AspNet.Routing public IEnumerable Constraints { get; private set; } /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + foreach (var constraint in Constraints) { if (!constraint.Match(httpContext, route, routeKey, values, routeDirection)) diff --git a/src/Microsoft.AspNet.Routing/Constraints/DateTimeRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/DateTimeRouteConstraint.cs index c1ece5151d..64777c590d 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/DateTimeRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/DateTimeRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -21,12 +20,33 @@ namespace Microsoft.AspNet.Routing.Constraints public class DateTimeRouteConstraint : IRouteConstraint { /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/DecimalRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/DecimalRouteConstraint.cs index 5befd14f9b..114d22dccb 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/DecimalRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/DecimalRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints public class DecimalRouteConstraint : IRouteConstraint { /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/DoubleRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/DoubleRouteConstraint.cs index 7bdaa40a8c..1a91446a7e 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/DoubleRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/DoubleRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints public class DoubleRouteConstraint : IRouteConstraint { /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/FloatRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/FloatRouteConstraint.cs index bc5249a792..21a5ac2292 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/FloatRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/FloatRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints public class FloatRouteConstraint : IRouteConstraint { /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/GuidRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/GuidRouteConstraint.cs index e1f2b2a1a2..d815f5ebd4 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/GuidRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/GuidRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -17,12 +16,33 @@ namespace Microsoft.AspNet.Routing.Constraints public class GuidRouteConstraint : IRouteConstraint { /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/IntRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/IntRouteConstraint.cs index 018f71049d..939b913d26 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/IntRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/IntRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints public class IntRouteConstraint : IRouteConstraint { /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/LengthRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/LengthRouteConstraint.cs index e449dff7d2..8978a328ab 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/LengthRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/LengthRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -72,12 +71,33 @@ namespace Microsoft.AspNet.Routing.Constraints public int MaxLength { get; private set; } /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/LongRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/LongRouteConstraint.cs index 5fed8f86a2..e7e8723ce6 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/LongRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/LongRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints public class LongRouteConstraint : IRouteConstraint { /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { @@ -31,7 +51,7 @@ namespace Microsoft.AspNet.Routing.Constraints long result; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); - return Int64.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); + return long.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); } return false; diff --git a/src/Microsoft.AspNet.Routing/Constraints/MaxLengthRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/MaxLengthRouteConstraint.cs index 4249b6a4f1..3027a94995 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/MaxLengthRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/MaxLengthRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -35,12 +34,33 @@ namespace Microsoft.AspNet.Routing.Constraints public int MaxLength { get; private set; } /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/MaxRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/MaxRouteConstraint.cs index fe5e27ba90..e2db3419c2 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/MaxRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/MaxRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -29,12 +28,33 @@ namespace Microsoft.AspNet.Routing.Constraints public long Max { get; private set; } /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/MinLengthRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/MinLengthRouteConstraint.cs index da4996b5aa..ee67aac988 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/MinLengthRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/MinLengthRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -35,12 +34,33 @@ namespace Microsoft.AspNet.Routing.Constraints public int MinLength { get; private set; } /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/MinRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/MinRouteConstraint.cs index 240e527a1d..7c50f70d41 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/MinRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/MinRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -29,12 +28,33 @@ namespace Microsoft.AspNet.Routing.Constraints public long Min { get; private set; } /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/OptionalRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/OptionalRouteConstraint.cs index 1af1820e02..ad6e3f7969 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/OptionalRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/OptionalRouteConstraint.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -12,19 +12,45 @@ namespace Microsoft.AspNet.Routing.Constraints /// public class OptionalRouteConstraint : IRouteConstraint { - public OptionalRouteConstraint([NotNull] IRouteConstraint innerConstraint) + public OptionalRouteConstraint(IRouteConstraint innerConstraint) { + if (innerConstraint == null) + { + throw new ArgumentNullException(nameof(innerConstraint)); + } + InnerConstraint = innerConstraint; } public IRouteConstraint InnerConstraint { get; } - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value)) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/RangeRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/RangeRouteConstraint.cs index fe080ab687..7b1bc6599c 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/RangeRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/RangeRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -43,12 +42,33 @@ namespace Microsoft.AspNet.Routing.Constraints public long Max { get; private set; } /// - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/Constraints/RegexInlineRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/RegexInlineRouteConstraint.cs index fc3d2d6541..d13469ef33 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/RegexInlineRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/RegexInlineRouteConstraint.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Internal; +using System; namespace Microsoft.AspNet.Routing.Constraints { @@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Routing.Constraints /// Initializes a new instance of the class. /// /// The regular expression pattern to match. - public RegexInlineRouteConstraint([NotNull] string regexPattern) + public RegexInlineRouteConstraint(string regexPattern) : base(regexPattern) { } diff --git a/src/Microsoft.AspNet.Routing/Constraints/RegexRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/RegexRouteConstraint.cs index 87d69eea5b..034ec58faf 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/RegexRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/RegexRouteConstraint.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Globalization; using System.Text.RegularExpressions; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -14,13 +13,23 @@ namespace Microsoft.AspNet.Routing.Constraints { private static readonly TimeSpan RegexMatchTimeout = TimeSpan.FromSeconds(10); - public RegexRouteConstraint([NotNull] Regex regex) + public RegexRouteConstraint(Regex regex) { + if (regex == null) + { + throw new ArgumentNullException(nameof(regex)); + } + Constraint = regex; } - public RegexRouteConstraint([NotNull] string regexPattern) + public RegexRouteConstraint(string regexPattern) { + if (regexPattern == null) + { + throw new ArgumentNullException(nameof(regexPattern)); + } + Constraint = new Regex( regexPattern, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase, @@ -29,12 +38,33 @@ namespace Microsoft.AspNet.Routing.Constraints public Regex Constraint { get; private set; } - public bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary routeValues, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary routeValues, + RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (routeValues == null) + { + throw new ArgumentNullException(nameof(routeValues)); + } + object routeValue; if (routeValues.TryGetValue(routeKey, out routeValue) diff --git a/src/Microsoft.AspNet.Routing/Constraints/RequiredRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/RequiredRouteConstraint.cs index 87d4db09af..03f46b00e9 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/RequiredRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/RequiredRouteConstraint.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Constraints { @@ -20,12 +19,32 @@ namespace Microsoft.AspNet.Routing.Constraints { /// public bool Match( - [NotNull]HttpContext httpContext, - [NotNull]IRouter route, - [NotNull]string routeKey, - [NotNull]IDictionary values, + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, RouteDirection routeDirection) { + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (routeKey == null) + { + throw new ArgumentNullException(nameof(routeKey)); + } + + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + object value; if (values.TryGetValue(routeKey, out value) && value != null) { diff --git a/src/Microsoft.AspNet.Routing/DefaultInlineConstraintResolver.cs b/src/Microsoft.AspNet.Routing/DefaultInlineConstraintResolver.cs index 68ecadd144..027537b3d5 100644 --- a/src/Microsoft.AspNet.Routing/DefaultInlineConstraintResolver.cs +++ b/src/Microsoft.AspNet.Routing/DefaultInlineConstraintResolver.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Reflection; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Routing @@ -39,8 +38,13 @@ namespace Microsoft.AspNet.Routing /// The entire string "arg1, arg2, 12" will be treated as a single argument. /// In all other cases arguments are split at comma. /// - public virtual IRouteConstraint ResolveConstraint([NotNull] string inlineConstraint) + public virtual IRouteConstraint ResolveConstraint(string inlineConstraint) { + if (inlineConstraint == null) + { + throw new ArgumentNullException(nameof(inlineConstraint)); + } + string constraintKey; string argumentString; var indexOfFirstOpenParens = inlineConstraint.IndexOf('('); diff --git a/src/Microsoft.AspNet.Routing/IInlineConstraintResolver.cs b/src/Microsoft.AspNet.Routing/IInlineConstraintResolver.cs index 2302795b0b..4f86d57dcc 100644 --- a/src/Microsoft.AspNet.Routing/IInlineConstraintResolver.cs +++ b/src/Microsoft.AspNet.Routing/IInlineConstraintResolver.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Internal; - namespace Microsoft.AspNet.Routing { /// @@ -15,6 +13,6 @@ namespace Microsoft.AspNet.Routing /// /// The inline constraint to resolve. /// The the inline constraint was resolved to. - IRouteConstraint ResolveConstraint([NotNull] string inlineConstraint); + IRouteConstraint ResolveConstraint(string inlineConstraint); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Routing/IRouteConstraint.cs b/src/Microsoft.AspNet.Routing/IRouteConstraint.cs index 22227a64e5..ac1558e6a1 100644 --- a/src/Microsoft.AspNet.Routing/IRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/IRouteConstraint.cs @@ -3,16 +3,15 @@ using System.Collections.Generic; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing { public interface IRouteConstraint { - bool Match([NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] string routeKey, - [NotNull] IDictionary values, + bool Match(HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, RouteDirection routeDirection); } } diff --git a/src/Microsoft.AspNet.Routing/InlineRouteParameterParser.cs b/src/Microsoft.AspNet.Routing/InlineRouteParameterParser.cs index 427a4f2caa..39129ecd7f 100644 --- a/src/Microsoft.AspNet.Routing/InlineRouteParameterParser.cs +++ b/src/Microsoft.AspNet.Routing/InlineRouteParameterParser.cs @@ -1,16 +1,21 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using Microsoft.AspNet.Routing.Template; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing { public static class InlineRouteParameterParser { - public static TemplatePart ParseRouteParameter([NotNull] string routeParameter) + public static TemplatePart ParseRouteParameter(string routeParameter) { + if (routeParameter == null) + { + throw new ArgumentNullException(nameof(routeParameter)); + } + if (routeParameter.Length == 0) { return TemplatePart.CreateParameter( diff --git a/src/Microsoft.AspNet.Routing/Logging/LoggerExtensions.cs b/src/Microsoft.AspNet.Routing/Logging/LoggerExtensions.cs index ec9887295e..5e2d088921 100644 --- a/src/Microsoft.AspNet.Routing/Logging/LoggerExtensions.cs +++ b/src/Microsoft.AspNet.Routing/Logging/LoggerExtensions.cs @@ -1,15 +1,20 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Internal; +using System; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Routing.Logging.Internal { public static class LoggerExtensions { - public static void WriteValues([NotNull] this ILogger logger, object values) + public static void WriteValues(this ILogger logger, object values) { + if (logger == null) + { + throw new ArgumentNullException(nameof(logger)); + } + logger.Log( logLevel: LogLevel.Verbose, eventId: 0, diff --git a/src/Microsoft.AspNet.Routing/RouteCollection.cs b/src/Microsoft.AspNet.Routing/RouteCollection.cs index 792b3d0098..378269c316 100644 --- a/src/Microsoft.AspNet.Routing/RouteCollection.cs +++ b/src/Microsoft.AspNet.Routing/RouteCollection.cs @@ -7,7 +7,6 @@ using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Routing @@ -31,8 +30,13 @@ namespace Microsoft.AspNet.Routing get { return _routes.Count; } } - public void Add([NotNull] IRouter router) + public void Add(IRouter router) { + if (router == null) + { + throw new ArgumentNullException(nameof(router)); + } + var namedRouter = router as INamedRouter; if (namedRouter != null) { diff --git a/src/Microsoft.AspNet.Routing/RouteConstraintBuilder.cs b/src/Microsoft.AspNet.Routing/RouteConstraintBuilder.cs index 66ded14168..b984ab889f 100644 --- a/src/Microsoft.AspNet.Routing/RouteConstraintBuilder.cs +++ b/src/Microsoft.AspNet.Routing/RouteConstraintBuilder.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Routing.Constraints; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing { @@ -28,9 +27,19 @@ namespace Microsoft.AspNet.Routing /// The . /// The display name (for use in error messages). public RouteConstraintBuilder( - [NotNull] IInlineConstraintResolver inlineConstraintResolver, - [NotNull] string displayName) + IInlineConstraintResolver inlineConstraintResolver, + string displayName) { + if (inlineConstraintResolver == null) + { + throw new ArgumentNullException(nameof(inlineConstraintResolver)); + } + + if (displayName == null) + { + throw new ArgumentNullException(nameof(displayName)); + } + _inlineConstraintResolver = inlineConstraintResolver; _displayName = displayName; @@ -84,8 +93,18 @@ namespace Microsoft.AspNet.Routing /// For example, the string Product[0-9]+ will be converted to the regular expression /// ^(Product[0-9]+). See for more details. /// - public void AddConstraint([NotNull] string key, [NotNull] object value) + public void AddConstraint(string key, object value) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + var constraint = value as IRouteConstraint; if (constraint == null) { @@ -117,8 +136,18 @@ namespace Microsoft.AspNet.Routing /// based on . See to register /// custom constraint types. /// - public void AddResolvedConstraint([NotNull] string key, [NotNull] string constraintText) + public void AddResolvedConstraint(string key, string constraintText) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + if (constraintText == null) + { + throw new ArgumentNullException(nameof(constraintText)); + } + var constraint = _inlineConstraintResolver.ResolveConstraint(constraintText); if (constraint == null) { @@ -137,9 +166,14 @@ namespace Microsoft.AspNet.Routing /// Sets the given key as optional. /// /// The key. - public void SetOptional([NotNull] string key) + public void SetOptional(string key) { - _optionalParameters.Add(key); + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + _optionalParameters.Add(key); } private void Add(string key, IRouteConstraint constraint) diff --git a/src/Microsoft.AspNet.Routing/RouteConstraintMatcher.cs b/src/Microsoft.AspNet.Routing/RouteConstraintMatcher.cs index 5d9c88cc17..1af56b4907 100644 --- a/src/Microsoft.AspNet.Routing/RouteConstraintMatcher.cs +++ b/src/Microsoft.AspNet.Routing/RouteConstraintMatcher.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Routing @@ -11,12 +11,32 @@ namespace Microsoft.AspNet.Routing public static class RouteConstraintMatcher { public static bool Match(IReadOnlyDictionary constraints, - [NotNull] IDictionary routeValues, - [NotNull] HttpContext httpContext, - [NotNull] IRouter route, - [NotNull] RouteDirection routeDirection, - [NotNull] ILogger logger) + IDictionary routeValues, + HttpContext httpContext, + IRouter route, + RouteDirection routeDirection, + ILogger logger) { + if (routeValues == null) + { + throw new ArgumentNullException(nameof(routeValues)); + } + + if (httpContext == null) + { + throw new ArgumentNullException(nameof(httpContext)); + } + + if (route == null) + { + throw new ArgumentNullException(nameof(route)); + } + + if (logger == null) + { + throw new ArgumentNullException(nameof(logger)); + } + if (constraints == null) { return true; diff --git a/src/Microsoft.AspNet.Routing/RouteContext.cs b/src/Microsoft.AspNet.Routing/RouteContext.cs index d658c67f70..0c19bcea69 100644 --- a/src/Microsoft.AspNet.Routing/RouteContext.cs +++ b/src/Microsoft.AspNet.Routing/RouteContext.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing { @@ -28,9 +27,13 @@ namespace Microsoft.AspNet.Routing { return _routeData; } - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(RouteData)); + } + _routeData = value; } } diff --git a/src/Microsoft.AspNet.Routing/RouteData.cs b/src/Microsoft.AspNet.Routing/RouteData.cs index 61ce60b5ad..4d734e3fb4 100644 --- a/src/Microsoft.AspNet.Routing/RouteData.cs +++ b/src/Microsoft.AspNet.Routing/RouteData.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing { @@ -26,8 +25,13 @@ namespace Microsoft.AspNet.Routing /// Creates a new instance with values copied from . /// /// The other instance to copy. - public RouteData([NotNull] RouteData other) + public RouteData(RouteData other) { + if (other == null) + { + throw new ArgumentNullException(nameof(other)); + } + DataTokens = new Dictionary(other.DataTokens, StringComparer.OrdinalIgnoreCase); Routers = new List(other.Routers); Values = new RouteValueDictionary(other.Values); diff --git a/src/Microsoft.AspNet.Routing/RouteOptions.cs b/src/Microsoft.AspNet.Routing/RouteOptions.cs index 034ca0fad4..aadb80a450 100644 --- a/src/Microsoft.AspNet.Routing/RouteOptions.cs +++ b/src/Microsoft.AspNet.Routing/RouteOptions.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Routing.Constraints; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing { @@ -28,9 +27,13 @@ namespace Microsoft.AspNet.Routing { return _constraintTypeMap; } - [param: NotNull] set { + if (value == null) + { + throw new ArgumentNullException(nameof(ConstraintMap)); + } + _constraintTypeMap = value; } } diff --git a/src/Microsoft.AspNet.Routing/RouteValueDictionary.cs b/src/Microsoft.AspNet.Routing/RouteValueDictionary.cs index e528c1ecdc..203bcc13b0 100644 --- a/src/Microsoft.AspNet.Routing/RouteValueDictionary.cs +++ b/src/Microsoft.AspNet.Routing/RouteValueDictionary.cs @@ -6,7 +6,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing { @@ -85,10 +84,15 @@ namespace Microsoft.AspNet.Routing } /// - public object this[[NotNull] string key] + public object this[string key] { get { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException(nameof(key)); + } + object value; _dictionary.TryGetValue(key, out value); return value; @@ -96,6 +100,11 @@ namespace Microsoft.AspNet.Routing set { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentNullException(nameof(key)); + } + _dictionary[key] = value; } } @@ -191,8 +200,13 @@ namespace Microsoft.AspNet.Routing } /// - public void Add([NotNull] string key, object value) + public void Add(string key, object value) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + _dictionary.Add(key, value); } @@ -209,16 +223,26 @@ namespace Microsoft.AspNet.Routing } /// - public bool ContainsKey([NotNull] string key) + public bool ContainsKey(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + return _dictionary.ContainsKey(key); } /// void ICollection>.CopyTo( - [NotNull] KeyValuePair[] array, + KeyValuePair[] array, int arrayIndex) { + if (array == null) + { + throw new ArgumentNullException(nameof(array)); + } + ((ICollection>)_dictionary).CopyTo(array, arrayIndex); } @@ -247,14 +271,24 @@ namespace Microsoft.AspNet.Routing } /// - public bool Remove([NotNull] string key) + public bool Remove(string key) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + return _dictionary.Remove(key); } /// - public bool TryGetValue([NotNull] string key, out object value) + public bool TryGetValue(string key, out object value) { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + return _dictionary.TryGetValue(key, out value); } } diff --git a/src/Microsoft.AspNet.Routing/ServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Routing/ServiceCollectionExtensions.cs index 38f4891331..e0786bfc42 100644 --- a/src/Microsoft.AspNet.Routing/ServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Routing/ServiceCollectionExtensions.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNet.Routing; -using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { @@ -19,8 +18,13 @@ namespace Microsoft.Framework.DependencyInjection /// An action to configure the . public static void ConfigureRouting( this IServiceCollection services, - [NotNull] Action setupAction) + Action setupAction) { + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + services.Configure(setupAction); } } diff --git a/src/Microsoft.AspNet.Routing/Template/InlineConstraint.cs b/src/Microsoft.AspNet.Routing/Template/InlineConstraint.cs index 4c5520f87f..437e0a5c08 100644 --- a/src/Microsoft.AspNet.Routing/Template/InlineConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Template/InlineConstraint.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Framework.Internal; +using System; namespace Microsoft.AspNet.Routing.Template { @@ -14,8 +14,13 @@ namespace Microsoft.AspNet.Routing.Template /// Creates a new . /// /// The constraint text. - public InlineConstraint([NotNull] string constraint) + public InlineConstraint(string constraint) { + if (constraint == null) + { + throw new ArgumentNullException(nameof(constraint)); + } + Constraint = constraint; } diff --git a/src/Microsoft.AspNet.Routing/Template/RouteTemplate.cs b/src/Microsoft.AspNet.Routing/Template/RouteTemplate.cs index 057e5b89d8..1fa863a69c 100644 --- a/src/Microsoft.AspNet.Routing/Template/RouteTemplate.cs +++ b/src/Microsoft.AspNet.Routing/Template/RouteTemplate.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Template { @@ -14,8 +13,13 @@ namespace Microsoft.AspNet.Routing.Template { private const string SeparatorString = "/"; - public RouteTemplate([NotNull] List segments) + public RouteTemplate(List segments) { + if (segments == null) + { + throw new ArgumentNullException(nameof(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 749291d753..ce64b9959f 100644 --- a/src/Microsoft.AspNet.Routing/Template/TemplateBinder.cs +++ b/src/Microsoft.AspNet.Routing/Template/TemplateBinder.cs @@ -8,7 +8,6 @@ using System.Globalization; using System.Text; using System.Text.RegularExpressions; using Microsoft.AspNet.Http.Extensions; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Template { @@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Routing.Template private readonly IReadOnlyDictionary _defaults; private readonly RouteTemplate _template; - public TemplateBinder([NotNull] RouteTemplate template, IReadOnlyDictionary defaults) + public TemplateBinder(RouteTemplate template, IReadOnlyDictionary defaults) { + if (template == null) + { + throw new ArgumentNullException(nameof(template)); + } + _template = template; _defaults = defaults; } @@ -216,7 +220,7 @@ namespace Microsoft.AspNet.Routing.Template // we won't necessarily add it to the URI we generate. if (!context.Buffer(converted)) { - return null; + return null; } } else @@ -353,8 +357,13 @@ namespace Microsoft.AspNet.Routing.Template public TemplateBindingContext( IReadOnlyDictionary defaults, - [NotNull] IDictionary values) + IDictionary values) { + if (values == null) + { + throw new ArgumentNullException(nameof(values)); + } + _defaults = defaults; _acceptedValues = new RouteValueDictionary(); diff --git a/src/Microsoft.AspNet.Routing/Template/TemplateMatcher.cs b/src/Microsoft.AspNet.Routing/Template/TemplateMatcher.cs index b7759ad66c..d8b0ab9b2b 100644 --- a/src/Microsoft.AspNet.Routing/Template/TemplateMatcher.cs +++ b/src/Microsoft.AspNet.Routing/Template/TemplateMatcher.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Template { @@ -16,9 +15,19 @@ namespace Microsoft.AspNet.Routing.Template private static readonly char[] Delimiters = new char[] { SeparatorChar }; public TemplateMatcher( - [NotNull] RouteTemplate template, - [NotNull] IReadOnlyDictionary defaults) + RouteTemplate template, + IReadOnlyDictionary defaults) { + if (template == null) + { + throw new ArgumentNullException(nameof(template)); + } + + if (defaults == null) + { + throw new ArgumentNullException(nameof(defaults)); + } + Template = template; Defaults = defaults ?? RouteValueDictionary.Empty; } @@ -27,8 +36,13 @@ namespace Microsoft.AspNet.Routing.Template public RouteTemplate Template { get; private set; } - public IDictionary Match([NotNull] string requestPath) + public IDictionary Match(string requestPath) { + if (requestPath == null) + { + throw new ArgumentNullException(nameof(requestPath)); + } + var requestSegments = requestPath.Split(Delimiters); var values = new RouteValueDictionary(); @@ -182,7 +196,7 @@ namespace Microsoft.AspNet.Routing.Template // In this case we start again from p2 to match the request and we succeed giving // the value bar to p2 if (routeSegment.Parts[indexOfLastSegment].IsOptional && - routeSegment.Parts[indexOfLastSegment - 1].IsOptionalSeperator) + routeSegment.Parts[indexOfLastSegment - 1].IsOptionalSeperator) { if (MatchComplexSegmentCore(routeSegment, requestSegment, Defaults, values, indexOfLastSegment)) { @@ -220,7 +234,7 @@ namespace Microsoft.AspNet.Routing.Template // Find last literal segment and get its last index in the string var lastIndex = requestSegment.Length; - + TemplatePart parameterNeedsValue = null; // Keeps track of a parameter segment that is pending a value TemplatePart lastLiteral = null; // Keeps track of the left-most literal we've encountered @@ -234,7 +248,7 @@ namespace Microsoft.AspNet.Routing.Template if (part.IsParameter) { // Hold on to the parameter so that we can fill it in when we locate the next literal - parameterNeedsValue = part; + parameterNeedsValue = part; } else { @@ -256,10 +270,10 @@ namespace Microsoft.AspNet.Routing.Template var indexOfLiteral = requestSegment.LastIndexOf(part.Text, startIndex, StringComparison.OrdinalIgnoreCase); - if (indexOfLiteral == -1) + if (indexOfLiteral == -1) { // If we couldn't find this literal index, this segment cannot match - return false; + return false; } // If the first subsegment is a literal, it must match at the right-most extent of the request URI. @@ -320,7 +334,7 @@ namespace Microsoft.AspNet.Routing.Template // For these segments all parameters must have non-empty values. If the parameter // has an empty value it's not a match. return false; - + } else { diff --git a/src/Microsoft.AspNet.Routing/Template/TemplatePart.cs b/src/Microsoft.AspNet.Routing/Template/TemplatePart.cs index aedc80b60e..1612ec1f0f 100644 --- a/src/Microsoft.AspNet.Routing/Template/TemplatePart.cs +++ b/src/Microsoft.AspNet.Routing/Template/TemplatePart.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing.Template { @@ -20,12 +20,17 @@ namespace Microsoft.AspNet.Routing.Template }; } - public static TemplatePart CreateParameter([NotNull] string name, + public static TemplatePart CreateParameter(string name, bool isCatchAll, bool isOptional, object defaultValue, IEnumerable inlineConstraints) { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + return new TemplatePart() { IsParameter = true, diff --git a/src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs b/src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs index 50e05c5f39..59db1c0c2c 100644 --- a/src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs +++ b/src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Internal; using Microsoft.Framework.Logging; namespace Microsoft.AspNet.Routing.Template @@ -25,36 +24,44 @@ namespace Microsoft.AspNet.Routing.Template private ILogger _constraintLogger; public TemplateRoute( - [NotNull] IRouter target, + IRouter target, string routeTemplate, IInlineConstraintResolver inlineConstraintResolver) - : this(target, - routeTemplate, - defaults: null, - constraints: null, - dataTokens: null, - inlineConstraintResolver: inlineConstraintResolver) + : this( + target, + routeTemplate, + defaults: null, + constraints: null, + dataTokens: null, + inlineConstraintResolver: inlineConstraintResolver) { } - public TemplateRoute([NotNull] IRouter target, - string routeTemplate, - IDictionary defaults, - IDictionary constraints, - IDictionary dataTokens, - IInlineConstraintResolver inlineConstraintResolver) + public TemplateRoute( + IRouter target, + string routeTemplate, + IDictionary defaults, + IDictionary constraints, + IDictionary dataTokens, + IInlineConstraintResolver inlineConstraintResolver) : this(target, null, routeTemplate, defaults, constraints, dataTokens, inlineConstraintResolver) { } - public TemplateRoute([NotNull] IRouter target, - string routeName, - string routeTemplate, - IDictionary defaults, - IDictionary constraints, - IDictionary dataTokens, - IInlineConstraintResolver inlineConstraintResolver) + public TemplateRoute( + IRouter target, + string routeName, + string routeTemplate, + IDictionary defaults, + IDictionary constraints, + IDictionary dataTokens, + IInlineConstraintResolver inlineConstraintResolver) { + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + _target = target; _routeTemplate = routeTemplate ?? string.Empty; Name = routeName; @@ -94,8 +101,13 @@ namespace Microsoft.AspNet.Routing.Template get { return _constraints; } } - public async virtual Task RouteAsync([NotNull] RouteContext context) + public async virtual Task RouteAsync(RouteContext context) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + EnsureLoggers(context.HttpContext); var requestPath = context.HttpContext.Request.Path.Value; diff --git a/src/Microsoft.AspNet.Routing/VirtualPathData.cs b/src/Microsoft.AspNet.Routing/VirtualPathData.cs index 5e30a01fd6..326afac34d 100644 --- a/src/Microsoft.AspNet.Routing/VirtualPathData.cs +++ b/src/Microsoft.AspNet.Routing/VirtualPathData.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Http; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Routing { @@ -21,7 +20,7 @@ namespace Microsoft.AspNet.Routing /// /// The object that is used to generate the URL. /// The generated URL. - public VirtualPathData([NotNull] IRouter router, string virtualPath) + public VirtualPathData(IRouter router, string virtualPath) : this(router, virtualPath, dataTokens: new RouteValueDictionary()) { } @@ -33,11 +32,10 @@ namespace Microsoft.AspNet.Routing /// The generated URL. /// The collection of custom values. public VirtualPathData( - [NotNull] IRouter router, + IRouter router, string virtualPath, IDictionary dataTokens) - : this(router, CreatePathString(virtualPath), dataTokens) - + : this(router, CreatePathString(virtualPath), dataTokens) { } @@ -48,10 +46,15 @@ namespace Microsoft.AspNet.Routing /// The generated URL. /// The collection of custom values. public VirtualPathData( - [NotNull] IRouter router, + IRouter router, PathString virtualPath, IDictionary dataTokens) { + if (router == null) + { + throw new ArgumentNullException(nameof(router)); + } + Router = router; VirtualPath = virtualPath; diff --git a/src/Microsoft.AspNet.Routing/project.json b/src/Microsoft.AspNet.Routing/project.json index 8c1ace8cd7..7643857a86 100644 --- a/src/Microsoft.AspNet.Routing/project.json +++ b/src/Microsoft.AspNet.Routing/project.json @@ -11,11 +11,7 @@ "dependencies": { "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.Framework.Logging.Abstractions": "1.0.0-*", - "Microsoft.Framework.OptionsModel": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Sources": { - "type": "build", - "version": "1.0.0-*" - } + "Microsoft.Framework.OptionsModel": "1.0.0-*" }, "frameworks": { "dnx451": { }, diff --git a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateMatcherTests.cs b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateMatcherTests.cs index 5868fd183d..d097d7779c 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateMatcherTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateMatcherTests.cs @@ -1,12 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 using System.Collections.Generic; -using Microsoft.AspNet.Routing.Constraints; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; -using Moq; using Xunit; namespace Microsoft.AspNet.Routing.Template.Tests @@ -921,7 +918,9 @@ namespace Microsoft.AspNet.Routing.Template.Tests IDictionary expected) { // Arrange - var matcher = new TemplateMatcher(TemplateParser.Parse(template), defaults); + var matcher = new TemplateMatcher( + TemplateParser.Parse(template), + defaults ?? new Dictionary()); // Act var match = matcher.Match(path); @@ -951,4 +950,3 @@ namespace Microsoft.AspNet.Routing.Template.Tests } } } -#endif