// 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.AspNetCore.Http; namespace Microsoft.AspNetCore.Routing.Constraints { /// /// Constrains a route by several child constraints. /// public class CompositeRouteConstraint : IRouteConstraint { /// /// Initializes a new instance of the class. /// /// The child constraints that must match for this constraint to match. public CompositeRouteConstraint(IEnumerable constraints) { if (constraints == null) { throw new ArgumentNullException(nameof(constraints)); } Constraints = constraints; } /// /// Gets the child constraints that must match for this constraint to match. /// public IEnumerable Constraints { get; private set; } /// public bool Match( HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection) { 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)) { return false; } } return true; } } }