Ejemplo n.º 1
0
        protected virtual RouteValueDictionary GetConstraints(RouteElement route)
        {
            try
            {
                var dictionary = GetDictionaryFromAttributes(route.Constraints.Attributes);

                for (var i = 0; i < route.Constraints.Count; i++)
                {
                    var constraint = route.Constraints[i];
                    var routeConstraintType = Type.GetType(constraint.Type);

                    IRouteConstraint routeConstraint;
                    if (constraint.Params.Attributes.Count > 0)
                    {
                        var parameters = constraint.Params.Attributes.Values.ToArray();
                        routeConstraint = (IRouteConstraint)Activator.CreateInstance(routeConstraintType, parameters);
                    }
                    else
                        routeConstraint = (IRouteConstraint)Activator.CreateInstance(routeConstraintType);

                    dictionary.Add(constraint.Name, routeConstraint);
                }

                return dictionary;
            }
            catch (Exception ex)
            {
                var message = String.Format("Can't create an instance of IRouteHandler {0}", route.RouteHandlerType);
                throw new ApplicationException(message, ex);
            }
        }
Ejemplo n.º 2
0
        protected virtual RouteValueDictionary GetDefaults(RouteElement route)
        {
            var dataTokensDictionary = new RouteValueDictionary();

            foreach (var dataToken in route.Defaults.Attributes)
                if (dataToken.Value.Equals(Optional, StringComparison.InvariantCultureIgnoreCase))
                    dataTokensDictionary.Add(dataToken.Key, UrlParameter.Optional);
                else
                    dataTokensDictionary.Add(dataToken.Key, dataToken.Value);

            return dataTokensDictionary;
        }
Ejemplo n.º 3
0
 protected virtual RouteValueDictionary GetDataTokens(RouteElement route)
 {
     return GetDictionaryFromAttributes(route.DataTokens.Attributes);
 }
Ejemplo n.º 4
0
        protected virtual IRouteHandler GetInstanceOfRouteHandler(RouteElement route)
        {
            if (String.IsNullOrEmpty(route.RouteHandlerType))
                return new MvcRouteHandler();

            try
            {
                Type routeHandlerType = Type.GetType(route.RouteHandlerType);
                return Activator.CreateInstance(routeHandlerType) as IRouteHandler;
            }
            catch (Exception ex)
            {
                var message = String.Format("Can't create an instance of IRouteHandler {0}", route.RouteHandlerType);
                throw new ApplicationException(message, ex);
            }
        }