StyleCop Fixes for routing.

This commit is contained in:
harshgMSFT 2014-06-12 18:25:07 -07:00
parent e223173869
commit 0ca5576926
13 changed files with 496 additions and 57 deletions

430
Settings.StyleCop Normal file
View File

@ -0,0 +1,430 @@
<StyleCopSettings Version="105">
<GlobalSettings>
<StringProperty Name="MergeSettingsFiles">NoMerge</StringProperty>
</GlobalSettings>
<Parsers>
<Parser ParserId="StyleCop.CSharp.CsParser">
<ParserSettings>
<BooleanProperty Name="AnalyzeDesignerFiles">False</BooleanProperty>
</ParserSettings>
</Parser>
</Parsers>
<Analyzers>
<Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
<Rules>
<Rule Name="FieldNamesMustNotBeginWithUnderscore">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldNamesMustNotUseHungarianNotation">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings>
<CollectionProperty Name="Hungarian">
<Value>as</Value>
<Value>db</Value>
<Value>dc</Value>
<Value>do</Value>
<Value>ef</Value>
<Value>id</Value>
<Value>if</Value>
<Value>in</Value>
<Value>is</Value>
<Value>my</Value>
<Value>no</Value>
<Value>on</Value>
<Value>sl</Value>
<Value>to</Value>
<Value>ui</Value>
<Value>vs</Value>
</CollectionProperty>
</AnalyzerSettings>
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
<Rules>
<Rule Name="FileMustHaveHeader">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustContainFileName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderFileNameDocumentationMustMatchFileName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustHaveValidCompanyText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ConstructorSummaryDocumentationMustBeginWithStandardText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DestructorSummaryDocumentationMustBeginWithStandardText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationHeadersMustNotContainBlankLines">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PartialElementsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="EnumerationItemsMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationMustContainValidXml">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustHaveSummary">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PartialElementDocumentationMustHaveSummary">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustHaveSummaryText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PartialElementDocumentationMustHaveSummaryText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustNotHaveDefaultSummary">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementParametersMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementParameterDocumentationMustMatchElementParameters">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementParameterDocumentationMustDeclareParameterName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementParameterDocumentationMustHaveText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementReturnValueMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementReturnValueDocumentationMustHaveText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="VoidReturnValueMustNotBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="GenericTypeParametersMustBeDocumented">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="GenericTypeParametersMustBeDocumentedPartialClass">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="GenericTypeParameterDocumentationMustMatchTypeParameters">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="GenericTypeParameterDocumentationMustDeclareParameterName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="GenericTypeParameterDocumentationMustHaveText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PropertySummaryDocumentationMustMatchAccessors">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PropertySummaryDocumentationMustOmitSetAccessorWithRestrictedAccess">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustNotBeCopiedAndPasted">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="SingleLineCommentsMustNotUseDocumentationStyleSlashes">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationTextMustNotBeEmpty">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationTextMustContainWhitespace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationMustMeetCharacterPercentage">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="IncludedDocumentationXPathDoesNotExist">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="IncludeNodeDoesNotContainValidFileAndPath">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="InheritDocMustBeUsedWithInheritingClass">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustShowCopyright">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustHaveCopyrightText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderFileNameDocumentationMustMatchTypeName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings>
<BooleanProperty Name="IgnorePrivates">True</BooleanProperty>
<BooleanProperty Name="IgnoreInternals">True</BooleanProperty>
</AnalyzerSettings>
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.ReadabilityRules">
<Rules>
<Rule Name="OpeningParenthesisMustBeOnDeclarationLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ParameterMustNotSpanMultipleLines">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="UseStringEmptyForEmptyStrings">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PrefixLocalCallsWithThis">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ParameterMustFollowComma">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="SplitParametersMustStartOnLineAfterDeclaration">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ParametersMustBeOnSameLineOrSeparateLines">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="UseBuiltInTypeAlias">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="Microsoft.Web.StyleCop.Rules">
<AnalyzerSettings>
<StringProperty Name="FileHeaderText"> Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.</StringProperty>
</AnalyzerSettings>
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.LayoutRules">
<Rules>
<Rule Name="AllAccessorsMustBeMultiLineOrSingleLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="SingleLineCommentsMustNotBeFollowedByBlankLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ClosingCurlyBracketMustBeFollowedByBlankLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="SingleLineCommentMustBePrecededByBlankLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustBeSeparatedByBlankLine">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.MaintainabilityRules">
<Rules>
<Rule Name="ConditionalExpressionsMustDeclarePrecedence">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldsMustBePrivate">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DebugAssertMustProvideMessageText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="StatementMustNotUseUnnecessaryParenthesis">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.OrderingRules">
<Rules>
<Rule Name="UsingDirectivesMustBePlacedWithinNamespace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustAppearInTheCorrectOrder">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustBeOrderedByAccess">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ConstantsMustAppearBeforeFields">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="StaticElementsMustAppearBeforeInstanceElements">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.SpacingRules">
<Rules>
<Rule Name="SingleLineCommentsMustBeginWithSingleSpace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<!-- Creates a lot of noise with anonymous objects -->
<Rule Name="OpeningCurlyBracketsMustBeSpacedCorrectly">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ClosingCurlyBracketsMustBeSpacedCorrectly">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.KRules.FileHeaderRule">
<Rules />
<AnalyzerSettings>
<StringProperty Name="FileHeaderText"> Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.</StringProperty>
</AnalyzerSettings>
</Analyzer>
<Analyzer AnalyzerId="StyleCop.KRules.LineLengthRule">
<Rules />
<AnalyzerSettings>
<IntegerProperty Name="LineLength">120</IntegerProperty>
</AnalyzerSettings>
</Analyzer>
</Analyzers>
</StyleCopSettings>

View File

@ -13,5 +13,4 @@ namespace Microsoft.AspNet.Builder
return builder;
}
}
}
}

View File

@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Routing.Constraints
}
int result;
string valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
var valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
return Int32.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out result);
}

View File

@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Routing
{
string constraintKey;
string argumentString;
int indexOfFirstOpenParens = inlineConstraint.IndexOf('(');
var indexOfFirstOpenParens = inlineConstraint.IndexOf('(');
if (indexOfFirstOpenParens >= 0 && inlineConstraint.EndsWith(")", StringComparison.Ordinal))
{
constraintKey = inlineConstraint.Substring(0, indexOfFirstOpenParens);
@ -92,9 +92,10 @@ namespace Microsoft.AspNet.Routing
}
else
{
string[] arguments = argumentString.Split(',').Select(argument => argument.Trim()).ToArray();
var arguments = argumentString.Split(',').Select(argument => argument.Trim()).ToArray();
var matchingConstructors = constructors.Where(ci => ci.GetParameters().Length == arguments.Length).ToArray();
var matchingConstructors = constructors.Where(ci => ci.GetParameters().Length == arguments.Length)
.ToArray();
var constructorMatches = matchingConstructors.Length;
if (constructorMatches == 0)
@ -122,7 +123,7 @@ namespace Microsoft.AspNet.Routing
private static object[] ConvertArguments(ParameterInfo[] parameterInfos, string[] arguments)
{
var parameters = new object[parameterInfos.Length];
for (int i = 0; i < parameterInfos.Length; i++)
for (var i = 0; i < parameterInfos.Length; i++)
{
var parameter = parameterInfos[i];
var parameterType = parameter.ParameterType;

View File

@ -43,8 +43,7 @@ namespace Microsoft.AspNet.Routing
isCatchAll: isCatchAll,
isOptional: isOptional,
defaultValue: null,
inlineConstraint: null
);
inlineConstraint: null);
}
var parameterName = parameterMatch.Groups["parameterName"].Value;

View File

@ -29,7 +29,8 @@ namespace Microsoft.AspNet.Routing
return null;
}
var constraints = new Dictionary<string, IRouteConstraint>(inputConstraints.Count, StringComparer.OrdinalIgnoreCase);
var constraints = new Dictionary<string, IRouteConstraint>(inputConstraints.Count,
StringComparer.OrdinalIgnoreCase);
foreach (var kvp in inputConstraints)
{

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Routing
}
set
{
if(value == null)
if (value == null)
{
throw new ArgumentNullException("value",
Resources.FormatPropertyOfTypeCannotBeNull(

View File

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Builder
{

View File

@ -28,7 +28,8 @@ namespace Microsoft.AspNet.Routing.Template
}
// Step 1: Get the list of values we're going to try to use to match and generate this URI
public IDictionary<string, object> GetAcceptedValues(IDictionary<string, object> ambientValues, IDictionary<string, object> values)
public IDictionary<string, object> GetAcceptedValues(IDictionary<string, object> ambientValues,
IDictionary<string, object> values)
{
var context = new TemplateBindingContext(_defaults, values);
@ -47,7 +48,8 @@ namespace Microsoft.AspNet.Routing.Template
var hasNewParameterValue = values.TryGetValue(parameterName, out newParameterValue);
object currentParameterValue = null;
var hasCurrentParameterValue = ambientValues != null && ambientValues.TryGetValue(parameterName, out currentParameterValue);
var hasCurrentParameterValue = ambientValues != null &&
ambientValues.TryGetValue(parameterName, out currentParameterValue);
if (hasNewParameterValue && hasCurrentParameterValue)
{
@ -73,7 +75,7 @@ namespace Microsoft.AspNet.Routing.Template
context.Accept(parameterName, currentParameterValue);
}
}
};
}
// Add all remaining new values to the list of values we will use for URI generation
foreach (var kvp in values)
@ -85,7 +87,7 @@ namespace Microsoft.AspNet.Routing.Template
}
// Accept all remaining default values if they match a required parameter
for (int i = 0; i < _template.Parameters.Count; i++)
for (var i = 0; i < _template.Parameters.Count; i++)
{
var parameter = _template.Parameters[i];
if (parameter.IsOptional || parameter.IsCatchAll)
@ -179,7 +181,7 @@ namespace Microsoft.AspNet.Routing.Template
acceptedValues.Remove(part.Name);
}
bool isSameAsDefault = false;
var isSameAsDefault = false;
object defaultValue;
if (_defaults != null && _defaults.TryGetValue(part.Name, out defaultValue))
{
@ -245,7 +247,7 @@ namespace Microsoft.AspNet.Routing.Template
private static string UriEncode(string str)
{
string escape = Uri.EscapeUriString(str);
var escape = Uri.EscapeUriString(str);
return Regex.Replace(escape, "([#;?:@&=+$,])", EscapeReservedCharacters);
}
@ -256,7 +258,7 @@ namespace Microsoft.AspNet.Routing.Template
private TemplatePart GetParameter(string name)
{
for (int i = 0; i < _template.Parameters.Count; i++)
for (var i = 0; i < _template.Parameters.Count; i++)
{
var parameter = _template.Parameters[i];
if (string.Equals(parameter.Name, name, StringComparison.OrdinalIgnoreCase))
@ -270,8 +272,8 @@ namespace Microsoft.AspNet.Routing.Template
private static bool RoutePartsEqual(object a, object b)
{
string sa = a as string;
string sb = b as string;
var sa = a as string;
var sb = b as string;
if (sa != null && sb != null)
{
@ -395,7 +397,6 @@ namespace Microsoft.AspNet.Routing.Template
BufferState = SegmentState.Beginning;
UriState = SegmentState.Beginning;
}
public SegmentState BufferState { get; private set; }

View File

@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Routing.Template
var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
for (int i = 0; i < requestSegments.Length; i++)
for (var i = 0; i < requestSegments.Length; i++)
{
var routeSegment = Template.Segments.Count > i ? Template.Segments[i] : null;
var requestSegment = requestSegments[i];
@ -100,7 +100,8 @@ namespace Microsoft.AspNet.Routing.Template
}
else if (part.IsOptional)
{
// This is optional (with no default value) - there's nothing to capture here, so just move on.
// This is optional (with no default value)
// - there's nothing to capture here, so just move on.
}
else
{
@ -120,7 +121,7 @@ namespace Microsoft.AspNet.Routing.Template
}
}
for (int i = requestSegments.Length; i < Template.Segments.Count; i++)
for (var i = requestSegments.Length; i < Template.Segments.Count; i++)
{
// We've matched the request path so far, but still have remaining route segments. These need
// to be all single-part parameter segments with default values or else they won't match.
@ -131,7 +132,6 @@ namespace Microsoft.AspNet.Routing.Template
return null;
}
var part = routeSegment.Parts[0];
if (part.IsLiteral)
{
@ -172,21 +172,24 @@ namespace Microsoft.AspNet.Routing.Template
return values;
}
private bool MatchComplexSegment(TemplateSegment routeSegment, string requestSegment, IDictionary<string, object> defaults, Dictionary<string, object> values)
private bool MatchComplexSegment(TemplateSegment routeSegment,
string requestSegment,
IDictionary<string, object> defaults,
Dictionary<string, object> values)
{
Contract.Assert(routeSegment != null);
Contract.Assert(routeSegment.Parts.Count > 1);
// Find last literal segment and get its last index in the string
int lastIndex = requestSegment.Length;
int indexOfLastSegmentUsed = routeSegment.Parts.Count - 1;
var lastIndex = requestSegment.Length;
var indexOfLastSegmentUsed = routeSegment.Parts.Count - 1;
TemplatePart parameterNeedsValue = null; // Keeps track of a parameter segment that is pending a value
TemplatePart lastLiteral = null; // Keeps track of the left-most literal we've encountered
while (indexOfLastSegmentUsed >= 0)
{
int newLastIndex = lastIndex;
var newLastIndex = lastIndex;
var part = routeSegment.Parts[indexOfLastSegmentUsed];
if (part.IsParameter)
@ -199,7 +202,7 @@ namespace Microsoft.AspNet.Routing.Template
Contract.Assert(part.IsLiteral);
lastLiteral = part;
int startIndex = lastIndex - 1;
var startIndex = lastIndex - 1;
// If we have a pending parameter subsegment, we must leave at least one character for that
if (parameterNeedsValue != null)
{
@ -211,7 +214,9 @@ namespace Microsoft.AspNet.Routing.Template
return false;
}
int indexOfLiteral = requestSegment.LastIndexOf(part.Text, startIndex, StringComparison.OrdinalIgnoreCase);
var indexOfLiteral = requestSegment.LastIndexOf(part.Text,
startIndex,
StringComparison.OrdinalIgnoreCase);
if (indexOfLiteral == -1)
{
// If we couldn't find this literal index, this segment cannot match
@ -232,7 +237,8 @@ namespace Microsoft.AspNet.Routing.Template
newLastIndex = indexOfLiteral;
}
if ((parameterNeedsValue != null) && (((lastLiteral != null) && (part.IsLiteral)) || (indexOfLastSegmentUsed == 0)))
if ((parameterNeedsValue != null) &&
(((lastLiteral != null) && (part.IsLiteral)) || (indexOfLastSegmentUsed == 0)))
{
// If we have a pending parameter that needs a value, grab that value
@ -267,7 +273,7 @@ namespace Microsoft.AspNet.Routing.Template
}
}
string parameterValueString = requestSegment.Substring(parameterStartIndex, parameterTextLength);
var parameterValueString = requestSegment.Substring(parameterStartIndex, parameterTextLength);
if (string.IsNullOrEmpty(parameterValueString))
{
@ -298,6 +304,5 @@ namespace Microsoft.AspNet.Routing.Template
// This check is related to the check we do earlier in this function for LiteralSubsegments.
return (lastIndex == 0) || routeSegment.Parts[0].IsParameter;
}
}
}

View File

@ -35,9 +35,10 @@ namespace Microsoft.AspNet.Routing.Template
{
if (context.Current == Separator)
{
// If we get here is means that there's a consecutive '/' character. Templates don't start with a '/' and
// parsing a segment consumes the separator.
throw new ArgumentException(Resources.TemplateRoute_CannotHaveConsecutiveSeparators, "routeTemplate");
// If we get here is means that there's a consecutive '/' character.
// Templates don't start with a '/' and parsing a segment consumes the separator.
throw new ArgumentException(Resources.TemplateRoute_CannotHaveConsecutiveSeparators,
"routeTemplate");
}
else
{
@ -153,8 +154,8 @@ namespace Microsoft.AspNet.Routing.Template
if (context.Current == CloseBrace)
{
// This is an 'escaped' brace in a parameter name, which is not allowed. We'll just accept it for now
// and let the validation code for the name find it.
// This is an 'escaped' brace in a parameter name, which is not allowed.
// We'll just accept it for now and let the validation code for the name find it.
}
else
{
@ -179,8 +180,6 @@ namespace Microsoft.AspNet.Routing.Template
var templatePart = InlineRouteParameterParser.ParseRouteParameter(rawParameter,
context.ConstraintResolver);
if (templatePart.IsCatchAll && templatePart.IsOptional)
{
context.Error = Resources.TemplateRoute_CatchAllCannotBeOptional;
@ -287,13 +286,15 @@ namespace Microsoft.AspNet.Routing.Template
private static bool IsAllValid(TemplateParserContext context, List<TemplateSegment> segments)
{
// A catch-all parameter must be the last part of the last segment
for (int i = 0; i < segments.Count; i++)
for (var i = 0; i < segments.Count; i++)
{
var segment = segments[i];
for (int j = 0; j < segment.Parts.Count; j++)
for (var j = 0; j < segment.Parts.Count; j++)
{
var part = segment.Parts[j];
if (part.IsParameter && part.IsCatchAll && (i != segments.Count - 1 || j != segment.Parts.Count - 1))
if (part.IsParameter &&
part.IsCatchAll &&
(i != segments.Count - 1 || j != segment.Parts.Count - 1))
{
context.Error = Resources.TemplateRoute_CatchAllMustBeLast;
return false;
@ -307,7 +308,7 @@ namespace Microsoft.AspNet.Routing.Template
private static bool IsSegmentValid(TemplateParserContext context, TemplateSegment segment)
{
// If a segment has multiple parts, then it can't contain a catch all.
for (int i = 0; i < segment.Parts.Count; i++)
for (var i = 0; i < segment.Parts.Count; i++)
{
var part = segment.Parts[i];
if (part.IsParameter && part.IsCatchAll && segment.Parts.Count > 1)
@ -318,7 +319,7 @@ namespace Microsoft.AspNet.Routing.Template
}
// if a segment has multiple parts, then the parameters can't be optional
for (int i = 0; i < segment.Parts.Count; i++)
for (var i = 0; i < segment.Parts.Count; i++)
{
var part = segment.Parts[i];
if (part.IsParameter && part.IsOptional && segment.Parts.Count > 1)
@ -330,7 +331,7 @@ namespace Microsoft.AspNet.Routing.Template
// A segment cannot containt two consecutive parameters
var isLastSegmentParameter = false;
for (int i = 0; i < segment.Parts.Count; i++)
for (var i = 0; i < segment.Parts.Count; i++)
{
var part = segment.Parts[i];
if (part.IsParameter && isLastSegmentParameter)
@ -349,23 +350,26 @@ namespace Microsoft.AspNet.Routing.Template
{
if (parameterName.Length == 0)
{
context.Error = String.Format(CultureInfo.CurrentCulture, Resources.TemplateRoute_InvalidParameterName, parameterName);
context.Error = String.Format(CultureInfo.CurrentCulture,
Resources.TemplateRoute_InvalidParameterName, parameterName);
return false;
}
for (int i = 0; i < parameterName.Length; i++)
for (var i = 0; i < parameterName.Length; i++)
{
var c = parameterName[i];
if (c == Separator || c == OpenBrace || c == CloseBrace || c == QuestionMark)
{
context.Error = String.Format(CultureInfo.CurrentCulture, Resources.TemplateRoute_InvalidParameterName, parameterName);
context.Error = String.Format(CultureInfo.CurrentCulture,
Resources.TemplateRoute_InvalidParameterName, parameterName);
return false;
}
}
if (!context.ParameterNames.Add(parameterName))
{
context.Error = String.Format(CultureInfo.CurrentCulture, Resources.TemplateRoute_RepeatedParameter, parameterName);
context.Error = String.Format(CultureInfo.CurrentCulture,
Resources.TemplateRoute_RepeatedParameter, parameterName);
return false;
}
@ -379,7 +383,8 @@ namespace Microsoft.AspNet.Routing.Template
if (literal.IndexOf(QuestionMark) != -1)
{
context.Error = String.Format(CultureInfo.CurrentCulture, Resources.TemplateRoute_InvalidLiteral, literal);
context.Error = String.Format(CultureInfo.CurrentCulture,
Resources.TemplateRoute_InvalidLiteral, literal);
return false;
}
@ -392,7 +397,6 @@ namespace Microsoft.AspNet.Routing.Template
routeTemplate.StartsWith("/", StringComparison.Ordinal);
}
private class TemplateParserContext
{
private readonly string _template;

View File

@ -198,8 +198,8 @@ namespace Microsoft.AspNet.Routing.Template
if (_defaults.ContainsKey(parameter.Name))
{
throw new InvalidOperationException(
Resources.
FormatTemplateRoute_CannotHaveDefaultValueSpecifiedInlineAndExplicitly(parameter.Name));
Resources
.FormatTemplateRoute_CannotHaveDefaultValueSpecifiedInlineAndExplicitly(parameter.Name));
}
else
{

View File

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;