// 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;
namespace Microsoft.AspNet.Mvc.Routing
{
///
/// An attribute which specifies a required route value for an action or controller.
///
/// When placed on an action, the route data of a request must match the expectations of the route
/// constraint in order for the action to be selected. See for
/// the expectations that must be satisfied by the route data.
///
/// When placed on a controller, unless overridden by the action, the constraint applies to all
/// actions defined by the controller.
///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public abstract class RouteConstraintAttribute : Attribute, IRouteConstraintProvider
{
///
/// Creates a new with set as
/// .
///
/// The route value key.
protected RouteConstraintAttribute(string routeKey)
{
if (routeKey == null)
{
throw new ArgumentNullException(nameof(routeKey));
}
RouteKey = routeKey;
RouteKeyHandling = RouteKeyHandling.DenyKey;
}
///
/// Creates a new with
/// set to .
///
/// The route value key.
/// The expected route value.
///
/// Set to true to negate this constraint on all actions that do not define a behavior for this route key.
///
protected RouteConstraintAttribute(
string routeKey,
string routeValue,
bool blockNonAttributedActions)
{
if (routeKey == null)
{
throw new ArgumentNullException(nameof(routeKey));
}
if (routeValue == null)
{
throw new ArgumentNullException(nameof(routeValue));
}
RouteKey = routeKey;
RouteValue = routeValue;
BlockNonAttributedActions = blockNonAttributedActions;
}
///
public string RouteKey { get; private set; }
///
public RouteKeyHandling RouteKeyHandling { get; private set; }
///
public string RouteValue { get; private set; }
///
public bool BlockNonAttributedActions { get; private set; }
}
}