当前位置: 首页>>代码示例>>C#>>正文


C# RouteValueDictionary.TryGetValue方法代码示例

本文整理汇总了C#中RouteValueDictionary.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# RouteValueDictionary.TryGetValue方法的具体用法?C# RouteValueDictionary.TryGetValue怎么用?C# RouteValueDictionary.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RouteValueDictionary的用法示例。


在下文中一共展示了RouteValueDictionary.TryGetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MergeRouteValues

 public static RouteValueDictionary MergeRouteValues(string actionName, string controllerName,
     RouteValueDictionary implicitRouteValues,
     RouteValueDictionary routeValues,
     bool includeImplicitMvcValues)
 {
     var routeValueDictionary = new RouteValueDictionary();
     if (includeImplicitMvcValues)
     {
         object obj;
         if (implicitRouteValues != null && implicitRouteValues.TryGetValue("action", out obj))
         {
             routeValueDictionary["action"] = obj;
         }
         if (implicitRouteValues != null && implicitRouteValues.TryGetValue("controller", out obj))
         {
             routeValueDictionary["controller"] = obj;
         }
     }
     if (routeValues != null)
     {
         foreach (var keyValuePair in GetRouteValues(routeValues))
         {
             routeValueDictionary[keyValuePair.Key] = keyValuePair.Value;
         }
     }
     if (actionName != null)
     {
         routeValueDictionary["action"] = actionName;
     }
     if (controllerName != null)
     {
         routeValueDictionary["controller"] = controllerName;
     }
     return routeValueDictionary;
 }
开发者ID:Cefa68000,项目名称:AttributeRouting,代码行数:35,代码来源:UrlHelperExtensions.cs

示例2: MergeRouteValues

 public static RouteValueDictionary MergeRouteValues(string actionName, string controllerName, RouteValueDictionary implicitRouteValues, RouteValueDictionary routeValues, bool includeImplicitMvcValues)
 {
     RouteValueDictionary dictionary = new RouteValueDictionary();
     if (includeImplicitMvcValues)
     {
         object obj2;
         if ((implicitRouteValues != null) && implicitRouteValues.TryGetValue("action", out obj2))
         {
             dictionary["action"] = obj2;
         }
         if ((implicitRouteValues != null) && implicitRouteValues.TryGetValue("controller", out obj2))
         {
             dictionary["controller"] = obj2;
         }
     }
     if (routeValues != null)
     {
         foreach (KeyValuePair<string, object> pair in GetRouteValues(routeValues))
         {
             dictionary[pair.Key] = pair.Value;
         }
     }
     if (actionName != null)
     {
         dictionary["action"] = actionName;
     }
     if (controllerName != null)
     {
         dictionary["controller"] = controllerName;
     }
     return dictionary;
 }
开发者ID:Godoy,项目名称:CMS,代码行数:32,代码来源:RouteValuesHelpers.cs

示例3: ExtractControllerAndActionParams

        private static void ExtractControllerAndActionParams(RouteValueDictionary routeValues, out object controllerName, out object actionName, RouteValueDictionary source)
        {
            const string controllerParamName = "controller";
            const string actionParamName = "action";

            source.TryGetValue(controllerParamName, out controllerName);
            source.TryGetValue(actionParamName, out actionName);

            source.Remove(controllerParamName);
            source.Remove(actionParamName);

            routeValues.Merge(source);
        }
开发者ID:VlaTo,项目名称:EmpRe.NET,代码行数:13,代码来源:RouteValueDictionaryExtension.cs

示例4: MergeRouteValues

        public static RouteValueDictionary MergeRouteValues(string actionName, string controllerName,
		                                                    RouteValueDictionary implicitRouteValues,
		                                                    RouteValueDictionary routeValues, bool includeImplicitMvcValues)
        {
            // Create a new dictionary containing implicit and auto-generated values
            var mergedRouteValues = new RouteValueDictionary();

            if (includeImplicitMvcValues)
            {
                // We only include MVC-specific values like 'controller' and 'action' if we are generating an action link.
                // If we are generating a route link [as to MapRoute("Foo", "any/url", new { controller = ... })], including
                // the current controller name will cause the route match to fail if the current controller is not the same
                // as the destination controller.

                object implicitValue;
                if (implicitRouteValues != null && implicitRouteValues.TryGetValue("action", out implicitValue))
                {
                    mergedRouteValues["action"] = implicitValue;
                }

                if (implicitRouteValues != null && implicitRouteValues.TryGetValue("controller", out implicitValue))
                {
                    mergedRouteValues["controller"] = implicitValue;
                }
            }

            // Merge values from the user's dictionary/object
            if (routeValues != null)
            {
                foreach (var routeElement in GetRouteValues(routeValues))
                {
                    mergedRouteValues[routeElement.Key] = routeElement.Value;
                }
            }

            // Merge explicit parameters when not null
            if (actionName != null)
            {
                mergedRouteValues["action"] = actionName;
            }

            if (controllerName != null)
            {
                mergedRouteValues["controller"] = controllerName;
            }

            return mergedRouteValues;
        }
开发者ID:mhinze,项目名称:msmvc,代码行数:48,代码来源:RouteValuesHelpers.cs

示例5: Match

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            object rawValue;

             if (!values.TryGetValue(parameterName, out rawValue)
            || rawValue == null) {

            return true;
             }

             if (this.ParameterType.IsInstanceOfType(rawValue)) {
            return true;
             }

             string attemptedValue = Convert.ToString(rawValue, CultureInfo.InvariantCulture);

             if (attemptedValue.Length == 0) {
            return true;
             }

             object parsedVal;

             if (!TryParse(httpContext, parameterName, rawValue, attemptedValue, CultureInfo.InvariantCulture, out parsedVal)) {
            return false;
             }

             if (routeDirection == RouteDirection.IncomingRequest) {
            values[parameterName] = parsedVal;
             }

             return true;
        }
开发者ID:brettveenstra,项目名称:MvcCodeRouting,代码行数:32,代码来源:TypeAwareRouteConstraint.cs

示例6: Match

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
#endif
        {
            if (parameterName == null)
            {
                throw Error.ArgumentNull("parameterName");
            }

            if (values == null)
            {
                throw Error.ArgumentNull("values");
            }

            object value;
            if (values.TryGetValue(parameterName, out value) && value != null)
            {
                long longValue;
                if (value is long)
                {
                    longValue = (long)value;
                    return longValue <= Max;
                }

                string valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
                if (Int64.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out longValue))
                {
                    return longValue <= Max;
                }
            }
            return false;
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:31,代码来源:MaxRouteConstraint.cs

示例7: GetVirtualPathForArea

        public static VirtualPathData GetVirtualPathForArea(this RouteCollection routes, RequestContext requestContext, string name, RouteValueDictionary values) {
            if (routes == null) {
                throw new ArgumentNullException("routes");
            }

            if (!String.IsNullOrEmpty(name)) {
                // the route name is a stronger qualifier than the area name, so just pipe it through
                return routes.GetVirtualPath(requestContext, name, values);
            }

            RouteValueDictionary valuesWithoutArea = values;

            string targetArea = null;
            if (values != null) {
                object targetAreaRawValue;
                if (values.TryGetValue("area", out targetAreaRawValue)) {
                    targetArea = targetAreaRawValue as string;

                    // replace the original RVD so that we don't end up with ?area=targetArea in the generated URL
                    valuesWithoutArea = new RouteValueDictionary(values);
                    valuesWithoutArea.Remove("area");
                }
                else {
                    // set target area to current area
                    if (requestContext != null) {
                        targetArea = AreaHelpers.GetAreaName(requestContext.RouteData);
                    }
                }
            }

            RouteCollection filteredRoutes = FilterRouteCollectionByArea(routes, targetArea);
            VirtualPathData vpd = filteredRoutes.GetVirtualPath(requestContext, valuesWithoutArea);
            return vpd;
        }
开发者ID:Marceli,项目名称:JQueryGridTest,代码行数:34,代码来源:RouteCollectionExtensions.cs

示例8: Match

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) {
            if (routeDirection == RouteDirection.UrlGeneration)
                return true;

            object value;
            if (values.TryGetValue(parameterName, out value)) {
                var parameterValue = Convert.ToString(value);

                var path = FindPath(parameterValue);
                if(path == null) {
                    return false;
                }

                IDictionary<string, string> routeValues;
                if (!_aliasHolder.GetMap("Orchard.Blogs").TryGetAlias(path, out routeValues)) {
                    return false;
                }

                var isBlog =
                    //routeValues.ContainsKey("area") &&
                    //routeValues["area"] == "Orchard.Blogs" &&
                    routeValues.ContainsKey("controller") &&
                    routeValues["controller"] == "Blog" &&
                    routeValues.ContainsKey("action") &&
                    routeValues["action"] == "Item"
                    ;

                return isBlog;
            }

            return false;
        }
开发者ID:SunRobin2015,项目名称:RobinWithOrchard,代码行数:32,代码来源:RsdConstraint.CS

示例9: GetVirtualPath

        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) {
            // only if MVC or WebApi match for this route
            object httpRouteValue;
            if (values.TryGetValue("httproute", out httpRouteValue)) {
                if (httpRouteValue is bool && (bool)httpRouteValue != IsHttpRoute) {
                    return null;
                }
            }

            // locate appropriate shell settings for request
            var settings = _runningShellTable.Match(requestContext.HttpContext);

            // only proceed if there was a match, and it was for this client
            if (settings == null || settings.Name != _shellSettings.Name)
                return null;

            var effectiveRequestContext = requestContext;
            if (_urlPrefix != null)
                effectiveRequestContext = new RequestContext(new UrlPrefixAdjustedHttpContext(requestContext.HttpContext, _urlPrefix), requestContext.RouteData);

            var virtualPath = _route.GetVirtualPath(effectiveRequestContext, values);
            if (virtualPath == null)
                return null;

            if (_urlPrefix != null)
                virtualPath.VirtualPath = _urlPrefix.PrependLeadingSegments(virtualPath.VirtualPath);

            return virtualPath;
        }
开发者ID:AndreVolksdorf,项目名称:Orchard,代码行数:29,代码来源:ShellRoute.cs

示例10: Match

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            if (routeDirection == RouteDirection.UrlGeneration)
            {
                return true;
            }

            object versionValue;
            if (!values.TryGetValue(parameterName, out versionValue))
            {
                return true;
            }

            if (versionValue == null || versionValue == UrlParameter.Optional)
            {
                return true;
            }

            string versionText = versionValue.ToString();
            if (versionText.Length == 0)
            {
                return true;
            }
            SemanticVersion ignored;
            return SemanticVersion.TryParse(versionText, out ignored);
        }
开发者ID:henrycomein,项目名称:NuGetGallery,代码行数:26,代码来源:VersionRouteConstraint.cs

示例11: Match

        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) {

            object value;
            if (values.TryGetValue(parameterName, out value)) {
                var parameterValue = Convert.ToString(value);

                var path = FindPath(parameterValue);
                if (path == null) {
                    return false;
                }

                var archiveData = FindArchiveData(parameterValue);
                if (archiveData == null) {
                    return false;
                }

                try {
                    // is this a valid date ?
                    archiveData.ToDateTime();
                }
                catch {
                    return false;
                }

                var autoroute = _pathResolutionService.GetPath(path);

                return autoroute != null && autoroute.Is<BlogPart>();
            }

            return false;
        }
开发者ID:Zlatinsz,项目名称:podnebeto,代码行数:31,代码来源:ArchiveConstraint.CS

示例12: Match

		protected virtual bool Match (HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
		{
			if (httpContext == null)
				throw new ArgumentNullException ("httpContext");
			if (route == null)
				throw new ArgumentNullException ("route");
			if (parameterName == null)
				throw new ArgumentNullException ("parameterName");
			if (values == null)
				throw new ArgumentNullException ("values");

			switch (routeDirection) {
			case RouteDirection.IncomingRequest:
				// LAMESPEC: .NET allows case-insensitive comparison, which violates RFC 2616
				return AllowedMethods.Contains (httpContext.Request.HttpMethod);

			case RouteDirection.UrlGeneration:
				// See: aspnetwebstack's WebAPI equivalent for details.
				object method;

				if (!values.TryGetValue (parameterName, out method))
					return true;

				// LAMESPEC: .NET allows case-insensitive comparison, which violates RFC 2616
				return AllowedMethods.Contains (Convert.ToString (method));

			default:
				throw new ArgumentException ("Invalid routeDirection: " + routeDirection);
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:30,代码来源:HttpMethodConstraint.cs

示例13: Match

 public bool Match(System.Web.HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
 {
     object val;
     values.TryGetValue(parameterName, out val);
     string input = Convert.ToString(val, CultureInfo.InvariantCulture);
     return regex.IsMatch(input);
 }
开发者ID:nuhusky,项目名称:gizmo-helpers,代码行数:7,代码来源:RegexConstraint.cs

示例14: GetAuthorizationContext

        public AuthorizationContext GetAuthorizationContext(RequestContext requestContext, string controllerName, string actionName, RouteValueDictionary routeValues)
        {
            object area;
            string areaName = string.Empty;
            string key = controllerName + " " + actionName;

            if (routeValues != null && routeValues.TryGetValue("Area", out area))
            {
                areaName = area.ToString();
                key = areaName + " " + key;
            }

            AuthorizationContext authorizationContext = cache.Get(key, () => AuthorizationContextFactory(requestContext, controllerName, actionName, areaName));

            if (authorizationContext == null)
            {
                return null;
            }

            authorizationContext.RequestContext = requestContext;
            authorizationContext.HttpContext = requestContext.HttpContext;
            authorizationContext.Result = null;

            return authorizationContext;
        }
开发者ID:vialpando09,项目名称:RallyPortal2,代码行数:25,代码来源:AuthorizationContextCache.cs

示例15: IsMatch

        protected override bool IsMatch(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            if (routeDirection == RouteDirection.UrlGeneration)
            {
                return true;
            }

            if (!base.IsMatch(httpContext, route, parameterName, values, routeDirection))
            {
                return false;
            }

            //First check that language matches regex pattern
            object parameterValue; 
            values.TryGetValue(parameterName, out parameterValue);
            var parameterValueString = Convert.ToString(parameterValue, CultureInfo.InvariantCulture);
            var constraintsRegEx = string.Format("^({0})$", Constants.LanguageRegex);
            if (!Regex.IsMatch(parameterValueString, constraintsRegEx, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Compiled))
            {
                return false;
            }

            try
            {
                var culture = CultureInfo.CreateSpecificCulture(parameterValueString);
                //If culture is created then it is correct
            }
            catch
            {
                //Language is not valid
                return false;
            }

            return true;
        }
开发者ID:gitter-badger,项目名称:vc-community-1.x,代码行数:35,代码来源:LanguageRouteConstraint.cs


注:本文中的RouteValueDictionary.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。