本文整理汇总了C#中HttpRouteValueDictionary.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRouteValueDictionary.Remove方法的具体用法?C# HttpRouteValueDictionary.Remove怎么用?C# HttpRouteValueDictionary.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRouteValueDictionary
的用法示例。
在下文中一共展示了HttpRouteValueDictionary.Remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bind
public BoundRouteTemplate Bind(IDictionary<string, object> currentValues, IDictionary<string, object> values, HttpRouteValueDictionary defaultValues, HttpRouteValueDictionary constraints)
{
if (currentValues == null)
{
currentValues = new HttpRouteValueDictionary();
}
if (values == null)
{
values = new HttpRouteValueDictionary();
}
if (defaultValues == null)
{
defaultValues = new HttpRouteValueDictionary();
}
// The set of values we should be using when generating the URI in this route
HttpRouteValueDictionary acceptedValues = new HttpRouteValueDictionary();
// Keep track of which new values have been used
HashSet<string> unusedNewValues = new HashSet<string>(values.Keys, StringComparer.OrdinalIgnoreCase);
// Step 1: Get the list of values we're going to try to use to match and generate this URI
// Find out which entries in the URI are valid for the URI we want to generate.
// If the URI had ordered parameters a="1", b="2", c="3" and the new values
// specified that b="9", then we need to invalidate everything after it. The new
// values should then be a="1", b="9", c=<no value>.
ForEachParameter(_pathSegments, delegate(PathParameterSubsegment parameterSubsegment)
{
// If it's a parameter subsegment, examine the current value to see if it matches the new value
string parameterName = parameterSubsegment.ParameterName;
object newParameterValue;
bool hasNewParameterValue = values.TryGetValue(parameterName, out newParameterValue);
if (hasNewParameterValue)
{
unusedNewValues.Remove(parameterName);
}
object currentParameterValue;
bool hasCurrentParameterValue = currentValues.TryGetValue(parameterName, out currentParameterValue);
if (hasNewParameterValue && hasCurrentParameterValue)
{
if (!RoutePartsEqual(currentParameterValue, newParameterValue))
{
// Stop copying current values when we find one that doesn't match
return false;
}
}
// If the parameter is a match, add it to the list of values we will use for URI generation
if (hasNewParameterValue)
{
if (IsRoutePartNonEmpty(newParameterValue))
{
acceptedValues.Add(parameterName, newParameterValue);
}
}
else
{
if (hasCurrentParameterValue)
{
acceptedValues.Add(parameterName, currentParameterValue);
}
}
return true;
});
// Add all remaining new values to the list of values we will use for URI generation
foreach (var newValue in values)
{
if (IsRoutePartNonEmpty(newValue.Value))
{
if (!acceptedValues.ContainsKey(newValue.Key))
{
acceptedValues.Add(newValue.Key, newValue.Value);
}
}
}
// Add all current values that aren't in the URI at all
foreach (var currentValue in currentValues)
{
string parameterName = currentValue.Key;
if (!acceptedValues.ContainsKey(parameterName))
{
PathParameterSubsegment parameterSubsegment = GetParameterSubsegment(_pathSegments, parameterName);
if (parameterSubsegment == null)
{
acceptedValues.Add(parameterName, currentValue.Value);
}
}
}
// Add all remaining default values from the route to the list of values we will use for URI generation
ForEachParameter(_pathSegments, delegate(PathParameterSubsegment parameterSubsegment)
{
//.........这里部分代码省略.........