Replacing NotNullAttribute with exceptions

This commit is contained in:
Pranav K 2015-09-10 22:16:45 -07:00
parent 7cd8db6695
commit c6941e797f
42 changed files with 772 additions and 218 deletions

View File

@ -1,15 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.AspNet.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Builder namespace Microsoft.AspNet.Builder
{ {
public static class BuilderExtensions 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<RouterMiddleware>(router); return builder.UseMiddleware<RouterMiddleware>(router);
} }
} }

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public class BoolRouteConstraint : IRouteConstraint public class BoolRouteConstraint : IRouteConstraint
{ {
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing namespace Microsoft.AspNet.Routing
{ {
@ -16,8 +16,13 @@ namespace Microsoft.AspNet.Routing
/// Initializes a new instance of the <see cref="CompositeRouteConstraint" /> class. /// Initializes a new instance of the <see cref="CompositeRouteConstraint" /> class.
/// </summary> /// </summary>
/// <param name="constraints">The child constraints that must match for this constraint to match.</param> /// <param name="constraints">The child constraints that must match for this constraint to match.</param>
public CompositeRouteConstraint([NotNull] IEnumerable<IRouteConstraint> constraints) public CompositeRouteConstraint(IEnumerable<IRouteConstraint> constraints)
{ {
if (constraints == null)
{
throw new ArgumentNullException(nameof(constraints));
}
Constraints = constraints; Constraints = constraints;
} }
@ -27,12 +32,33 @@ namespace Microsoft.AspNet.Routing
public IEnumerable<IRouteConstraint> Constraints { get; private set; } public IEnumerable<IRouteConstraint> Constraints { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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) foreach (var constraint in Constraints)
{ {
if (!constraint.Match(httpContext, route, routeKey, values, routeDirection)) if (!constraint.Match(httpContext, route, routeKey, values, routeDirection))

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -21,12 +20,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public class DateTimeRouteConstraint : IRouteConstraint public class DateTimeRouteConstraint : IRouteConstraint
{ {
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public class DecimalRouteConstraint : IRouteConstraint public class DecimalRouteConstraint : IRouteConstraint
{ {
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public class DoubleRouteConstraint : IRouteConstraint public class DoubleRouteConstraint : IRouteConstraint
{ {
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public class FloatRouteConstraint : IRouteConstraint public class FloatRouteConstraint : IRouteConstraint
{ {
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -17,12 +16,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public class GuidRouteConstraint : IRouteConstraint public class GuidRouteConstraint : IRouteConstraint
{ {
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public class IntRouteConstraint : IRouteConstraint public class IntRouteConstraint : IRouteConstraint
{ {
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -72,12 +71,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public int MaxLength { get; private set; } public int MaxLength { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -15,12 +14,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public class LongRouteConstraint : IRouteConstraint public class LongRouteConstraint : IRouteConstraint
{ {
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {
@ -31,7 +51,7 @@ namespace Microsoft.AspNet.Routing.Constraints
long result; long result;
var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); 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; return false;

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -35,12 +34,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public int MaxLength { get; private set; } public int MaxLength { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -29,12 +28,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public long Max { get; private set; } public long Max { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -35,12 +34,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public int MinLength { get; private set; } public int MinLength { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -29,12 +28,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public long Min { get; private set; } public long Min { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -12,19 +12,45 @@ namespace Microsoft.AspNet.Routing.Constraints
/// </summary> /// </summary>
public class OptionalRouteConstraint : IRouteConstraint public class OptionalRouteConstraint : IRouteConstraint
{ {
public OptionalRouteConstraint([NotNull] IRouteConstraint innerConstraint) public OptionalRouteConstraint(IRouteConstraint innerConstraint)
{ {
if (innerConstraint == null)
{
throw new ArgumentNullException(nameof(innerConstraint));
}
InnerConstraint = innerConstraint; InnerConstraint = innerConstraint;
} }
public IRouteConstraint InnerConstraint { get; } public IRouteConstraint InnerConstraint { get; }
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value)) if (values.TryGetValue(routeKey, out value))
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -43,12 +42,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public long Max { get; private set; } public long Max { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> values, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Routing.Constraints
/// Initializes a new instance of the <see cref="RegexInlineRouteConstraint" /> class. /// Initializes a new instance of the <see cref="RegexInlineRouteConstraint" /> class.
/// </summary> /// </summary>
/// <param name="regexPattern">The regular expression pattern to match.</param> /// <param name="regexPattern">The regular expression pattern to match.</param>
public RegexInlineRouteConstraint([NotNull] string regexPattern) public RegexInlineRouteConstraint(string regexPattern)
: base(regexPattern) : base(regexPattern)
{ {
} }

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -14,13 +13,23 @@ namespace Microsoft.AspNet.Routing.Constraints
{ {
private static readonly TimeSpan RegexMatchTimeout = TimeSpan.FromSeconds(10); 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; Constraint = regex;
} }
public RegexRouteConstraint([NotNull] string regexPattern) public RegexRouteConstraint(string regexPattern)
{ {
if (regexPattern == null)
{
throw new ArgumentNullException(nameof(regexPattern));
}
Constraint = new Regex( Constraint = new Regex(
regexPattern, regexPattern,
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
@ -29,12 +38,33 @@ namespace Microsoft.AspNet.Routing.Constraints
public Regex Constraint { get; private set; } public Regex Constraint { get; private set; }
public bool Match([NotNull] HttpContext httpContext, public bool Match(
[NotNull] IRouter route, HttpContext httpContext,
[NotNull] string routeKey, IRouter route,
[NotNull] IDictionary<string, object> routeValues, string routeKey,
RouteDirection routeDirection) IDictionary<string, object> 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; object routeValue;
if (routeValues.TryGetValue(routeKey, out routeValue) if (routeValues.TryGetValue(routeKey, out routeValue)

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Constraints namespace Microsoft.AspNet.Routing.Constraints
{ {
@ -20,12 +19,32 @@ namespace Microsoft.AspNet.Routing.Constraints
{ {
/// <inheritdoc /> /// <inheritdoc />
public bool Match( public bool Match(
[NotNull]HttpContext httpContext, HttpContext httpContext,
[NotNull]IRouter route, IRouter route,
[NotNull]string routeKey, string routeKey,
[NotNull]IDictionary<string, object> values, IDictionary<string, object> values,
RouteDirection routeDirection) 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; object value;
if (values.TryGetValue(routeKey, out value) && value != null) if (values.TryGetValue(routeKey, out value) && value != null)
{ {

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Routing 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. /// The entire string "arg1, arg2, 12" will be treated as a single argument.
/// In all other cases arguments are split at comma. /// In all other cases arguments are split at comma.
/// </example> /// </example>
public virtual IRouteConstraint ResolveConstraint([NotNull] string inlineConstraint) public virtual IRouteConstraint ResolveConstraint(string inlineConstraint)
{ {
if (inlineConstraint == null)
{
throw new ArgumentNullException(nameof(inlineConstraint));
}
string constraintKey; string constraintKey;
string argumentString; string argumentString;
var indexOfFirstOpenParens = inlineConstraint.IndexOf('('); var indexOfFirstOpenParens = inlineConstraint.IndexOf('(');

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 namespace Microsoft.AspNet.Routing
{ {
/// <summary> /// <summary>
@ -15,6 +13,6 @@ namespace Microsoft.AspNet.Routing
/// </summary> /// </summary>
/// <param name="inlineConstraint">The inline constraint to resolve.</param> /// <param name="inlineConstraint">The inline constraint to resolve.</param>
/// <returns>The <see cref="IRouteConstraint"/> the inline constraint was resolved to.</returns> /// <returns>The <see cref="IRouteConstraint"/> the inline constraint was resolved to.</returns>
IRouteConstraint ResolveConstraint([NotNull] string inlineConstraint); IRouteConstraint ResolveConstraint(string inlineConstraint);
} }
} }

View File

@ -3,16 +3,15 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing namespace Microsoft.AspNet.Routing
{ {
public interface IRouteConstraint public interface IRouteConstraint
{ {
bool Match([NotNull] HttpContext httpContext, bool Match(HttpContext httpContext,
[NotNull] IRouter route, IRouter route,
[NotNull] string routeKey, string routeKey,
[NotNull] IDictionary<string, object> values, IDictionary<string, object> values,
RouteDirection routeDirection); RouteDirection routeDirection);
} }
} }

View File

@ -1,16 +1,21 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.Collections.Generic;
using Microsoft.AspNet.Routing.Template; using Microsoft.AspNet.Routing.Template;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing namespace Microsoft.AspNet.Routing
{ {
public static class InlineRouteParameterParser 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) if (routeParameter.Length == 0)
{ {
return TemplatePart.CreateParameter( return TemplatePart.CreateParameter(

View File

@ -1,15 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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; using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Routing.Logging.Internal namespace Microsoft.AspNet.Routing.Logging.Internal
{ {
public static class LoggerExtensions 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( logger.Log(
logLevel: LogLevel.Verbose, logLevel: LogLevel.Verbose,
eventId: 0, eventId: 0,

View File

@ -7,7 +7,6 @@ using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Routing namespace Microsoft.AspNet.Routing
@ -31,8 +30,13 @@ namespace Microsoft.AspNet.Routing
get { return _routes.Count; } 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; var namedRouter = router as INamedRouter;
if (namedRouter != null) if (namedRouter != null)
{ {

View File

@ -4,7 +4,6 @@
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
{ {
@ -28,9 +27,19 @@ namespace Microsoft.AspNet.Routing
/// <param name="inlineConstraintResolver">The <see cref="IInlineConstraintResolver"/>.</param> /// <param name="inlineConstraintResolver">The <see cref="IInlineConstraintResolver"/>.</param>
/// <param name="displayName">The display name (for use in error messages).</param> /// <param name="displayName">The display name (for use in error messages).</param>
public RouteConstraintBuilder( public RouteConstraintBuilder(
[NotNull] IInlineConstraintResolver inlineConstraintResolver, IInlineConstraintResolver inlineConstraintResolver,
[NotNull] string displayName) string displayName)
{ {
if (inlineConstraintResolver == null)
{
throw new ArgumentNullException(nameof(inlineConstraintResolver));
}
if (displayName == null)
{
throw new ArgumentNullException(nameof(displayName));
}
_inlineConstraintResolver = inlineConstraintResolver; _inlineConstraintResolver = inlineConstraintResolver;
_displayName = displayName; _displayName = displayName;
@ -84,8 +93,18 @@ namespace Microsoft.AspNet.Routing
/// For example, the string <code>Product[0-9]+</code> will be converted to the regular expression /// For example, the string <code>Product[0-9]+</code> will be converted to the regular expression
/// <code>^(Product[0-9]+)</code>. See <see cref="System.Text.RegularExpressions.Regex"/> for more details. /// <code>^(Product[0-9]+)</code>. See <see cref="System.Text.RegularExpressions.Regex"/> for more details.
/// </remarks> /// </remarks>
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; var constraint = value as IRouteConstraint;
if (constraint == null) if (constraint == null)
{ {
@ -117,8 +136,18 @@ namespace Microsoft.AspNet.Routing
/// based on <paramref name="constraintText"/>. See <see cref="RouteOptions.ConstraintMap"/> to register /// based on <paramref name="constraintText"/>. See <see cref="RouteOptions.ConstraintMap"/> to register
/// custom constraint types. /// custom constraint types.
/// </remarks> /// </remarks>
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); var constraint = _inlineConstraintResolver.ResolveConstraint(constraintText);
if (constraint == null) if (constraint == null)
{ {
@ -137,9 +166,14 @@ namespace Microsoft.AspNet.Routing
/// Sets the given key as optional. /// Sets the given key as optional.
/// </summary> /// </summary>
/// <param name="key">The key.</param> /// <param name="key">The key.</param>
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) private void Add(string key, IRouteConstraint constraint)

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Routing namespace Microsoft.AspNet.Routing
@ -11,12 +11,32 @@ namespace Microsoft.AspNet.Routing
public static class RouteConstraintMatcher public static class RouteConstraintMatcher
{ {
public static bool Match(IReadOnlyDictionary<string, IRouteConstraint> constraints, public static bool Match(IReadOnlyDictionary<string, IRouteConstraint> constraints,
[NotNull] IDictionary<string, object> routeValues, IDictionary<string, object> routeValues,
[NotNull] HttpContext httpContext, HttpContext httpContext,
[NotNull] IRouter route, IRouter route,
[NotNull] RouteDirection routeDirection, RouteDirection routeDirection,
[NotNull] ILogger logger) 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) if (constraints == null)
{ {
return true; return true;

View File

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

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing namespace Microsoft.AspNet.Routing
{ {
@ -26,8 +25,13 @@ namespace Microsoft.AspNet.Routing
/// Creates a new <see cref="RouteData"/> instance with values copied from <paramref name="other"/>. /// Creates a new <see cref="RouteData"/> instance with values copied from <paramref name="other"/>.
/// </summary> /// </summary>
/// <param name="other">The other <see cref="RouteData"/> instance to copy.</param> /// <param name="other">The other <see cref="RouteData"/> instance to copy.</param>
public RouteData([NotNull] RouteData other) public RouteData(RouteData other)
{ {
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
DataTokens = new Dictionary<string, object>(other.DataTokens, StringComparer.OrdinalIgnoreCase); DataTokens = new Dictionary<string, object>(other.DataTokens, StringComparer.OrdinalIgnoreCase);
Routers = new List<IRouter>(other.Routers); Routers = new List<IRouter>(other.Routers);
Values = new RouteValueDictionary(other.Values); Values = new RouteValueDictionary(other.Values);

View File

@ -4,7 +4,6 @@
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
{ {
@ -28,9 +27,13 @@ namespace Microsoft.AspNet.Routing
{ {
return _constraintTypeMap; return _constraintTypeMap;
} }
[param: NotNull]
set set
{ {
if (value == null)
{
throw new ArgumentNullException(nameof(ConstraintMap));
}
_constraintTypeMap = value; _constraintTypeMap = value;
} }
} }

View File

@ -6,7 +6,6 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing namespace Microsoft.AspNet.Routing
{ {
@ -85,10 +84,15 @@ namespace Microsoft.AspNet.Routing
} }
/// <inheritdoc /> /// <inheritdoc />
public object this[[NotNull] string key] public object this[string key]
{ {
get get
{ {
if (string.IsNullOrEmpty(key))
{
throw new ArgumentNullException(nameof(key));
}
object value; object value;
_dictionary.TryGetValue(key, out value); _dictionary.TryGetValue(key, out value);
return value; return value;
@ -96,6 +100,11 @@ namespace Microsoft.AspNet.Routing
set set
{ {
if (string.IsNullOrEmpty(key))
{
throw new ArgumentNullException(nameof(key));
}
_dictionary[key] = value; _dictionary[key] = value;
} }
} }
@ -191,8 +200,13 @@ namespace Microsoft.AspNet.Routing
} }
/// <inheritdoc /> /// <inheritdoc />
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); _dictionary.Add(key, value);
} }
@ -209,16 +223,26 @@ namespace Microsoft.AspNet.Routing
} }
/// <inheritdoc /> /// <inheritdoc />
public bool ContainsKey([NotNull] string key) public bool ContainsKey(string key)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _dictionary.ContainsKey(key); return _dictionary.ContainsKey(key);
} }
/// <inheritdoc /> /// <inheritdoc />
void ICollection<KeyValuePair<string, object>>.CopyTo( void ICollection<KeyValuePair<string, object>>.CopyTo(
[NotNull] KeyValuePair<string, object>[] array, KeyValuePair<string, object>[] array,
int arrayIndex) int arrayIndex)
{ {
if (array == null)
{
throw new ArgumentNullException(nameof(array));
}
((ICollection<KeyValuePair<string, object>>)_dictionary).CopyTo(array, arrayIndex); ((ICollection<KeyValuePair<string, object>>)_dictionary).CopyTo(array, arrayIndex);
} }
@ -247,14 +271,24 @@ namespace Microsoft.AspNet.Routing
} }
/// <inheritdoc /> /// <inheritdoc />
public bool Remove([NotNull] string key) public bool Remove(string key)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _dictionary.Remove(key); return _dictionary.Remove(key);
} }
/// <inheritdoc /> /// <inheritdoc />
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); return _dictionary.TryGetValue(key, out value);
} }
} }

View File

@ -3,7 +3,6 @@
using System; using System;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection namespace Microsoft.Framework.DependencyInjection
{ {
@ -19,8 +18,13 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="setupAction">An action to configure the <see cref="RouteOptions"/>.</param> /// <param name="setupAction">An action to configure the <see cref="RouteOptions"/>.</param>
public static void ConfigureRouting( public static void ConfigureRouting(
this IServiceCollection services, this IServiceCollection services,
[NotNull] Action<RouteOptions> setupAction) Action<RouteOptions> setupAction)
{ {
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
services.Configure(setupAction); services.Configure(setupAction);
} }
} }

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 namespace Microsoft.AspNet.Routing.Template
{ {
@ -14,8 +14,13 @@ namespace Microsoft.AspNet.Routing.Template
/// Creates a new <see cref="InlineConstraint"/>. /// Creates a new <see cref="InlineConstraint"/>.
/// </summary> /// </summary>
/// <param name="constraint">The constraint text.</param> /// <param name="constraint">The constraint text.</param>
public InlineConstraint([NotNull] string constraint) public InlineConstraint(string constraint)
{ {
if (constraint == null)
{
throw new ArgumentNullException(nameof(constraint));
}
Constraint = constraint; Constraint = constraint;
} }

View File

@ -5,7 +5,6 @@ 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
{ {
@ -14,8 +13,13 @@ namespace Microsoft.AspNet.Routing.Template
{ {
private const string SeparatorString = "/"; private const string SeparatorString = "/";
public RouteTemplate([NotNull] List<TemplateSegment> segments) public RouteTemplate(List<TemplateSegment> segments)
{ {
if (segments == null)
{
throw new ArgumentNullException(nameof(segments));
}
Segments = segments; Segments = segments;
Parameters = new List<TemplatePart>(); Parameters = new List<TemplatePart>();

View File

@ -8,7 +8,6 @@ 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
{ {
@ -17,8 +16,13 @@ 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([NotNull] RouteTemplate template, IReadOnlyDictionary<string, object> defaults) public TemplateBinder(RouteTemplate template, IReadOnlyDictionary<string, object> defaults)
{ {
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
_template = template; _template = template;
_defaults = defaults; _defaults = defaults;
} }
@ -216,7 +220,7 @@ namespace Microsoft.AspNet.Routing.Template
// we won't necessarily add it to the URI we generate. // we won't necessarily add it to the URI we generate.
if (!context.Buffer(converted)) if (!context.Buffer(converted))
{ {
return null; return null;
} }
} }
else else
@ -353,8 +357,13 @@ namespace Microsoft.AspNet.Routing.Template
public TemplateBindingContext( public TemplateBindingContext(
IReadOnlyDictionary<string, object> defaults, IReadOnlyDictionary<string, object> defaults,
[NotNull] IDictionary<string, object> values) IDictionary<string, object> values)
{ {
if (values == null)
{
throw new ArgumentNullException(nameof(values));
}
_defaults = defaults; _defaults = defaults;
_acceptedValues = new RouteValueDictionary(); _acceptedValues = new RouteValueDictionary();

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing.Template namespace Microsoft.AspNet.Routing.Template
{ {
@ -16,9 +15,19 @@ namespace Microsoft.AspNet.Routing.Template
private static readonly char[] Delimiters = new char[] { SeparatorChar }; private static readonly char[] Delimiters = new char[] { SeparatorChar };
public TemplateMatcher( public TemplateMatcher(
[NotNull] RouteTemplate template, RouteTemplate template,
[NotNull] IReadOnlyDictionary<string, object> defaults) IReadOnlyDictionary<string, object> defaults)
{ {
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
if (defaults == null)
{
throw new ArgumentNullException(nameof(defaults));
}
Template = template; Template = template;
Defaults = defaults ?? RouteValueDictionary.Empty; Defaults = defaults ?? RouteValueDictionary.Empty;
} }
@ -27,8 +36,13 @@ namespace Microsoft.AspNet.Routing.Template
public RouteTemplate Template { get; private set; } public RouteTemplate Template { get; private set; }
public IDictionary<string, object> Match([NotNull] string requestPath) public IDictionary<string, object> Match(string requestPath)
{ {
if (requestPath == null)
{
throw new ArgumentNullException(nameof(requestPath));
}
var requestSegments = requestPath.Split(Delimiters); var requestSegments = requestPath.Split(Delimiters);
var values = new RouteValueDictionary(); 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 // In this case we start again from p2 to match the request and we succeed giving
// the value bar to p2 // the value bar to p2
if (routeSegment.Parts[indexOfLastSegment].IsOptional && if (routeSegment.Parts[indexOfLastSegment].IsOptional &&
routeSegment.Parts[indexOfLastSegment - 1].IsOptionalSeperator) routeSegment.Parts[indexOfLastSegment - 1].IsOptionalSeperator)
{ {
if (MatchComplexSegmentCore(routeSegment, requestSegment, Defaults, values, indexOfLastSegment)) 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 // Find last literal segment and get its last index in the string
var lastIndex = requestSegment.Length; var lastIndex = requestSegment.Length;
TemplatePart parameterNeedsValue = null; // Keeps track of a parameter segment that is pending a value 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 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) if (part.IsParameter)
{ {
// Hold on to the parameter so that we can fill it in when we locate the next literal // Hold on to the parameter so that we can fill it in when we locate the next literal
parameterNeedsValue = part; parameterNeedsValue = part;
} }
else else
{ {
@ -256,10 +270,10 @@ namespace Microsoft.AspNet.Routing.Template
var indexOfLiteral = requestSegment.LastIndexOf(part.Text, var indexOfLiteral = requestSegment.LastIndexOf(part.Text,
startIndex, startIndex,
StringComparison.OrdinalIgnoreCase); StringComparison.OrdinalIgnoreCase);
if (indexOfLiteral == -1) if (indexOfLiteral == -1)
{ {
// If we couldn't find this literal index, this segment cannot match // 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. // 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 // For these segments all parameters must have non-empty values. If the parameter
// has an empty value it's not a match. // has an empty value it's not a match.
return false; return false;
} }
else else
{ {

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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.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
{ {
@ -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 isCatchAll,
bool isOptional, bool isOptional,
object defaultValue, object defaultValue,
IEnumerable<InlineConstraint> inlineConstraints) IEnumerable<InlineConstraint> inlineConstraints)
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return new TemplatePart() return new TemplatePart()
{ {
IsParameter = true, IsParameter = true,

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Routing.Template namespace Microsoft.AspNet.Routing.Template
@ -25,36 +24,44 @@ namespace Microsoft.AspNet.Routing.Template
private ILogger _constraintLogger; private ILogger _constraintLogger;
public TemplateRoute( public TemplateRoute(
[NotNull] IRouter target, IRouter target,
string routeTemplate, string routeTemplate,
IInlineConstraintResolver inlineConstraintResolver) IInlineConstraintResolver inlineConstraintResolver)
: this(target, : this(
routeTemplate, target,
defaults: null, routeTemplate,
constraints: null, defaults: null,
dataTokens: null, constraints: null,
inlineConstraintResolver: inlineConstraintResolver) dataTokens: null,
inlineConstraintResolver: inlineConstraintResolver)
{ {
} }
public TemplateRoute([NotNull] IRouter target, public TemplateRoute(
string routeTemplate, IRouter target,
IDictionary<string, object> defaults, string routeTemplate,
IDictionary<string, object> constraints, IDictionary<string, object> defaults,
IDictionary<string, object> dataTokens, IDictionary<string, object> constraints,
IInlineConstraintResolver inlineConstraintResolver) IDictionary<string, object> dataTokens,
IInlineConstraintResolver inlineConstraintResolver)
: this(target, null, routeTemplate, defaults, constraints, dataTokens, inlineConstraintResolver) : this(target, null, routeTemplate, defaults, constraints, dataTokens, inlineConstraintResolver)
{ {
} }
public TemplateRoute([NotNull] IRouter target, public TemplateRoute(
string routeName, IRouter target,
string routeTemplate, string routeName,
IDictionary<string, object> defaults, string routeTemplate,
IDictionary<string, object> constraints, IDictionary<string, object> defaults,
IDictionary<string, object> dataTokens, IDictionary<string, object> constraints,
IInlineConstraintResolver inlineConstraintResolver) IDictionary<string, object> dataTokens,
IInlineConstraintResolver inlineConstraintResolver)
{ {
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
_target = target; _target = target;
_routeTemplate = routeTemplate ?? string.Empty; _routeTemplate = routeTemplate ?? string.Empty;
Name = routeName; Name = routeName;
@ -94,8 +101,13 @@ namespace Microsoft.AspNet.Routing.Template
get { return _constraints; } 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); EnsureLoggers(context.HttpContext);
var requestPath = context.HttpContext.Request.Path.Value; var requestPath = context.HttpContext.Request.Path.Value;

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Routing namespace Microsoft.AspNet.Routing
{ {
@ -21,7 +20,7 @@ namespace Microsoft.AspNet.Routing
/// </summary> /// </summary>
/// <param name="router">The object that is used to generate the URL.</param> /// <param name="router">The object that is used to generate the URL.</param>
/// <param name="virtualPath">The generated URL.</param> /// <param name="virtualPath">The generated URL.</param>
public VirtualPathData([NotNull] IRouter router, string virtualPath) public VirtualPathData(IRouter router, string virtualPath)
: this(router, virtualPath, dataTokens: new RouteValueDictionary()) : this(router, virtualPath, dataTokens: new RouteValueDictionary())
{ {
} }
@ -33,11 +32,10 @@ namespace Microsoft.AspNet.Routing
/// <param name="virtualPath">The generated URL.</param> /// <param name="virtualPath">The generated URL.</param>
/// <param name="dataTokens">The collection of custom values.</param> /// <param name="dataTokens">The collection of custom values.</param>
public VirtualPathData( public VirtualPathData(
[NotNull] IRouter router, IRouter router,
string virtualPath, string virtualPath,
IDictionary<string, object> dataTokens) IDictionary<string, object> dataTokens)
: this(router, CreatePathString(virtualPath), dataTokens) : this(router, CreatePathString(virtualPath), dataTokens)
{ {
} }
@ -48,10 +46,15 @@ namespace Microsoft.AspNet.Routing
/// <param name="virtualPath">The generated URL.</param> /// <param name="virtualPath">The generated URL.</param>
/// <param name="dataTokens">The collection of custom values.</param> /// <param name="dataTokens">The collection of custom values.</param>
public VirtualPathData( public VirtualPathData(
[NotNull] IRouter router, IRouter router,
PathString virtualPath, PathString virtualPath,
IDictionary<string, object> dataTokens) IDictionary<string, object> dataTokens)
{ {
if (router == null)
{
throw new ArgumentNullException(nameof(router));
}
Router = router; Router = router;
VirtualPath = virtualPath; VirtualPath = virtualPath;

View File

@ -11,11 +11,7 @@
"dependencies": { "dependencies": {
"Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*",
"Microsoft.Framework.Logging.Abstractions": "1.0.0-*", "Microsoft.Framework.Logging.Abstractions": "1.0.0-*",
"Microsoft.Framework.OptionsModel": "1.0.0-*", "Microsoft.Framework.OptionsModel": "1.0.0-*"
"Microsoft.Framework.NotNullAttribute.Sources": {
"type": "build",
"version": "1.0.0-*"
}
}, },
"frameworks": { "frameworks": {
"dnx451": { }, "dnx451": { },

View File

@ -1,12 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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 System.Collections.Generic;
using Microsoft.AspNet.Routing.Constraints;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
using Moq;
using Xunit; using Xunit;
namespace Microsoft.AspNet.Routing.Template.Tests namespace Microsoft.AspNet.Routing.Template.Tests
@ -921,7 +918,9 @@ namespace Microsoft.AspNet.Routing.Template.Tests
IDictionary<string, object> expected) IDictionary<string, object> expected)
{ {
// Arrange // Arrange
var matcher = new TemplateMatcher(TemplateParser.Parse(template), defaults); var matcher = new TemplateMatcher(
TemplateParser.Parse(template),
defaults ?? new Dictionary<string, object>());
// Act // Act
var match = matcher.Match(path); var match = matcher.Match(path);
@ -951,4 +950,3 @@ namespace Microsoft.AspNet.Routing.Template.Tests
} }
} }
} }
#endif