Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Fixing the issue #123
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmugdha committed Nov 18, 2014
1 parent 5c116db commit 455d908
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Microsoft.AspNet.Routing/OptionalRouteConstraint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.Collections.Generic;
using Microsoft.AspNet.Http;

namespace Microsoft.AspNet.Routing
{
public class OptionalRouteConstraint : IRouteConstraint
{
public OptionalRouteConstraint([NotNull]IRouteConstraint innerConstraint)
{
InnerConstraint = innerConstraint;
}

public IRouteConstraint InnerConstraint { get; private set; }

public bool Match([NotNull]HttpContext httpContext,
[NotNull]IRouter route,
[NotNull]string routeKey,
[NotNull]IDictionary<string, object> values,
RouteDirection routeDirection)
{
object value;
if (values.TryGetValue(routeKey, out value) && value != null)
{
return InnerConstraint.Match(httpContext,
route,
routeKey,
values,
routeDirection);
}

return true;
}
}
}

0 comments on commit 455d908

Please sign in to comment.