예제 #1
0
        private IEnumerable <RouteConstraintModel> ProcessConstraints(ITabContext context, MvcRoute route,
                                                                      Dictionary <int, Dictionary <int, List <ProcessConstraintMessage> > > constraintMessages)
        {
            if (route.Constraints == null || route.Constraints.Count == 0)
            {
                return(null);
            }

            Dictionary <int, List <ProcessConstraintMessage> > counstraintRouteMessages =
                constraintMessages.GetValueOrDefault(route.GetHashCode());

            List <RouteConstraintModel> result = new List <RouteConstraintModel>();

            foreach (KeyValuePair <string, object> constraint in route.Constraints)
            {
                RouteConstraintModel model = new RouteConstraintModel();
                model.ParameterName = constraint.Key;
                model.Constraint    = constraint.Value.ToString();

                if (counstraintRouteMessages != null)
                {
                    ProcessConstraintMessage counstraintMessage =
                        SafeFirstOrDefault(counstraintRouteMessages.GetValueOrDefault(constraint.Value.GetHashCode()));
                    model.IsMatch = false;

                    if (counstraintMessage != null)
                    {
                        model.IsMatch = counstraintMessage.IsMatch;
                    }
                }

                result.Add(model);
            }

            return(result);
        }