本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}