Skip to content

Instantly share code, notes, and snippets.

@rarous
Created July 15, 2011 09:09
Show Gist options
  • Select an option

  • Save rarous/1084363 to your computer and use it in GitHub Desktop.

Select an option

Save rarous/1084363 to your computer and use it in GitHub Desktop.
public class GuidConstraint : IRouteConstraint
{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (!values.ContainsKey(parameterName))
return false;
string stringValue = values[parameterName] as string;
if (string.IsNullOrEmpty(stringValue))
return false;
Guid guidValue;
return Guid.TryParse(stringValue, out guidValue) && (guidValue != Guid.Empty);
}
}
public class GuidConstraint : IRouteConstraint {
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (values.ContainsKey(parameterName))
{
string stringValue = values[parameterName] as string;
if (!string.IsNullOrEmpty(stringValue))
{
Guid guidValue;
return Guid.TryParse(stringValue, out guidValue) && (guidValue != Guid.Empty);
}
}
return false;
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment