コード例 #1
0
ファイル: RouteManager.cs プロジェクト: keith9820/Groundfloor
        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);
            }
        }
コード例 #2
0
ファイル: RouteManager.cs プロジェクト: keith9820/Groundfloor
        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;
        }
コード例 #3
0
ファイル: RouteManager.cs プロジェクト: keith9820/Groundfloor
 protected virtual RouteValueDictionary GetDataTokens(RouteElement route)
 {
     return GetDictionaryFromAttributes(route.DataTokens.Attributes);
 }
コード例 #4
0
ファイル: RouteManager.cs プロジェクト: keith9820/Groundfloor
        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);
            }
        }