// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; namespace Microsoft.AspNet.Mvc { /// /// Constraints an action to a route key and value. /// public class RouteDataActionConstraint { private RouteDataActionConstraint(string routeKey) { if (routeKey == null) { throw new ArgumentNullException(nameof(routeKey)); } RouteKey = routeKey; } /// /// Initializes a with a key and value, that are /// required to make the action match. /// /// The route key. /// The route value. /// /// Passing a or to /// is a way to express that routing cannot produce a value for this key. /// public RouteDataActionConstraint(string routeKey, string routeValue) : this(routeKey) { RouteValue = routeValue ?? string.Empty; if (string.IsNullOrEmpty(routeValue)) { KeyHandling = RouteKeyHandling.DenyKey; } else { KeyHandling = RouteKeyHandling.RequireKey; } } /// /// Create a catch all constraint for the given key. /// /// Route key. /// a that represents a catch all constraint. public static RouteDataActionConstraint CreateCatchAll(string routeKey) { var c = new RouteDataActionConstraint(routeKey); c.KeyHandling = RouteKeyHandling.CatchAll; c.RouteValue = string.Empty; return c; } /// /// The route key this constraint matches against. /// public string RouteKey { get; private set; } /// /// The route value this constraint matches against. /// public string RouteValue { get; private set; } /// /// The key handling definition for this constraint. /// public RouteKeyHandling KeyHandling { get; private set; } } }