Repository navigation
Expand file tree
/
Copy pathConstraintValidation.cs
More file actions
52 lines (46 loc) · 1.76 KB
/
Copy pathConstraintValidation.cs
File metadata and controls
52 lines (46 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// 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.Diagnostics.Contracts;
using System.Web.Mvc.Properties;
using System.Web.Routing;
namespace System.Web.Mvc.Routing
{
/// <summary>
/// Validates that the constraints on a Route are of a type that can be processed by <see cref="System.Web.Routing.Route" />.
/// </summary>
/// <remarks>
/// This validation is only applicable when the <see cref="System.Web.Routing.Route" /> is one that we created. A user-defined
/// type that is derived from <see cref="System.Web.Routing.RouteBase" /> may have different semantics.
///
/// The logic here is duplicated from System.Web, but we need it to validate correctness of routes on startup. Since we can't
/// change System.Web, this just lives in a static class for MVC.
/// </remarks>
internal static class ConstraintValidation
{
public static void Validate(Route route)
{
Contract.Assert(route != null);
Contract.Assert(route.Url != null);
if (route.Constraints == null)
{
return;
}
foreach (var kvp in route.Constraints)
{
if (kvp.Value is string)
{
continue;
}
if (kvp.Value is IRouteConstraint)
{
continue;
}
throw Error.InvalidOperation(
MvcResources.Route_InvalidConstraint,
kvp.Key,
route.Url,
typeof(IRouteConstraint).FullName);
}
}
}
}