Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Commit 0ca5576

Browse files
committed
StyleCop Fixes for routing.
1 parent e223173 commit 0ca5576

13 files changed

+496
-57
lines changed

Settings.StyleCop

Lines changed: 430 additions & 0 deletions
Large diffs are not rendered by default.

src/Microsoft.AspNet.Routing/BuilderExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ public static IBuilder UseRouter([NotNull] this IBuilder builder, [NotNull] IRou
1313
return builder;
1414
}
1515
}
16-
}
17-
16+
}

src/Microsoft.AspNet.Routing/Constraints/IntRouteConstraint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public bool Match([NotNull] HttpContext httpContext,
2929
}
3030

3131
int result;
32-
string valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
32+
var valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
3333
return Int32.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out result);
3434
}
3535

src/Microsoft.AspNet.Routing/DefaultInlineConstraintResolver.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public virtual IRouteConstraint ResolveConstraint([NotNull] string inlineConstra
4040
{
4141
string constraintKey;
4242
string argumentString;
43-
int indexOfFirstOpenParens = inlineConstraint.IndexOf('(');
43+
var indexOfFirstOpenParens = inlineConstraint.IndexOf('(');
4444
if (indexOfFirstOpenParens >= 0 && inlineConstraint.EndsWith(")", StringComparison.Ordinal))
4545
{
4646
constraintKey = inlineConstraint.Substring(0, indexOfFirstOpenParens);
@@ -92,9 +92,10 @@ private static IRouteConstraint CreateConstraint(Type constraintType, string arg
9292
}
9393
else
9494
{
95-
string[] arguments = argumentString.Split(',').Select(argument => argument.Trim()).ToArray();
95+
var arguments = argumentString.Split(',').Select(argument => argument.Trim()).ToArray();
9696

97-
var matchingConstructors = constructors.Where(ci => ci.GetParameters().Length == arguments.Length).ToArray();
97+
var matchingConstructors = constructors.Where(ci => ci.GetParameters().Length == arguments.Length)
98+
.ToArray();
9899
var constructorMatches = matchingConstructors.Length;
99100

100101
if (constructorMatches == 0)
@@ -122,7 +123,7 @@ private static IRouteConstraint CreateConstraint(Type constraintType, string arg
122123
private static object[] ConvertArguments(ParameterInfo[] parameterInfos, string[] arguments)
123124
{
124125
var parameters = new object[parameterInfos.Length];
125-
for (int i = 0; i < parameterInfos.Length; i++)
126+
for (var i = 0; i < parameterInfos.Length; i++)
126127
{
127128
var parameter = parameterInfos[i];
128129
var parameterType = parameter.ParameterType;

src/Microsoft.AspNet.Routing/InlineRouteParameterParser.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public static TemplatePart ParseRouteParameter([NotNull] string routeParameter,
4343
isCatchAll: isCatchAll,
4444
isOptional: isOptional,
4545
defaultValue: null,
46-
inlineConstraint: null
47-
);
46+
inlineConstraint: null);
4847
}
4948

5049
var parameterName = parameterMatch.Groups["parameterName"].Value;

src/Microsoft.AspNet.Routing/RouteConstraintBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ private static IDictionary<string, IRouteConstraint>
2929
return null;
3030
}
3131

32-
var constraints = new Dictionary<string, IRouteConstraint>(inputConstraints.Count, StringComparer.OrdinalIgnoreCase);
32+
var constraints = new Dictionary<string, IRouteConstraint>(inputConstraints.Count,
33+
StringComparer.OrdinalIgnoreCase);
3334

3435
foreach (var kvp in inputConstraints)
3536
{

src/Microsoft.AspNet.Routing/RouteOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public IDictionary<string, Type> ConstraintMap
1919
}
2020
set
2121
{
22-
if(value == null)
22+
if (value == null)
2323
{
2424
throw new ArgumentNullException("value",
2525
Resources.FormatPropertyOfTypeCannotBeNull(

src/Microsoft.AspNet.Routing/RouterMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System.Threading.Tasks;
45
using Microsoft.AspNet.Http;
56
using Microsoft.AspNet.Routing;
6-
using System.Threading.Tasks;
77

88
namespace Microsoft.AspNet.Builder
99
{

src/Microsoft.AspNet.Routing/Template/TemplateBinder.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public TemplateBinder(Template template, IDictionary<string, object> defaults)
2828
}
2929

3030
// Step 1: Get the list of values we're going to try to use to match and generate this URI
31-
public IDictionary<string, object> GetAcceptedValues(IDictionary<string, object> ambientValues, IDictionary<string, object> values)
31+
public IDictionary<string, object> GetAcceptedValues(IDictionary<string, object> ambientValues,
32+
IDictionary<string, object> values)
3233
{
3334
var context = new TemplateBindingContext(_defaults, values);
3435

@@ -47,7 +48,8 @@ public IDictionary<string, object> GetAcceptedValues(IDictionary<string, object>
4748
var hasNewParameterValue = values.TryGetValue(parameterName, out newParameterValue);
4849

4950
object currentParameterValue = null;
50-
var hasCurrentParameterValue = ambientValues != null && ambientValues.TryGetValue(parameterName, out currentParameterValue);
51+
var hasCurrentParameterValue = ambientValues != null &&
52+
ambientValues.TryGetValue(parameterName, out currentParameterValue);
5153

5254
if (hasNewParameterValue && hasCurrentParameterValue)
5355
{
@@ -73,7 +75,7 @@ public IDictionary<string, object> GetAcceptedValues(IDictionary<string, object>
7375
context.Accept(parameterName, currentParameterValue);
7476
}
7577
}
76-
};
78+
}
7779

7880
// Add all remaining new values to the list of values we will use for URI generation
7981
foreach (var kvp in values)
@@ -85,7 +87,7 @@ public IDictionary<string, object> GetAcceptedValues(IDictionary<string, object>
8587
}
8688

8789
// Accept all remaining default values if they match a required parameter
88-
for (int i = 0; i < _template.Parameters.Count; i++)
90+
for (var i = 0; i < _template.Parameters.Count; i++)
8991
{
9092
var parameter = _template.Parameters[i];
9193
if (parameter.IsOptional || parameter.IsCatchAll)
@@ -179,7 +181,7 @@ public string BindValues(IDictionary<string, object> acceptedValues)
179181
acceptedValues.Remove(part.Name);
180182
}
181183

182-
bool isSameAsDefault = false;
184+
var isSameAsDefault = false;
183185
object defaultValue;
184186
if (_defaults != null && _defaults.TryGetValue(part.Name, out defaultValue))
185187
{
@@ -245,7 +247,7 @@ public string BindValues(IDictionary<string, object> acceptedValues)
245247

246248
private static string UriEncode(string str)
247249
{
248-
string escape = Uri.EscapeUriString(str);
250+
var escape = Uri.EscapeUriString(str);
249251
return Regex.Replace(escape, "([#;?:@&=+$,])", EscapeReservedCharacters);
250252
}
251253

@@ -256,7 +258,7 @@ private static string EscapeReservedCharacters(Match m)
256258

257259
private TemplatePart GetParameter(string name)
258260
{
259-
for (int i = 0; i < _template.Parameters.Count; i++)
261+
for (var i = 0; i < _template.Parameters.Count; i++)
260262
{
261263
var parameter = _template.Parameters[i];
262264
if (string.Equals(parameter.Name, name, StringComparison.OrdinalIgnoreCase))
@@ -270,8 +272,8 @@ private TemplatePart GetParameter(string name)
270272

271273
private static bool RoutePartsEqual(object a, object b)
272274
{
273-
string sa = a as string;
274-
string sb = b as string;
275+
var sa = a as string;
276+
var sb = b as string;
275277

276278
if (sa != null && sb != null)
277279
{
@@ -395,7 +397,6 @@ public UriBuildingContext()
395397

396398
BufferState = SegmentState.Beginning;
397399
UriState = SegmentState.Beginning;
398-
399400
}
400401

401402
public SegmentState BufferState { get; private set; }

src/Microsoft.AspNet.Routing/Template/TemplateMatcher.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public IDictionary<string, object> Match(string requestPath, IDictionary<string,
3737

3838
var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
3939

40-
for (int i = 0; i < requestSegments.Length; i++)
40+
for (var i = 0; i < requestSegments.Length; i++)
4141
{
4242
var routeSegment = Template.Segments.Count > i ? Template.Segments[i] : null;
4343
var requestSegment = requestSegments[i];
@@ -100,7 +100,8 @@ public IDictionary<string, object> Match(string requestPath, IDictionary<string,
100100
}
101101
else if (part.IsOptional)
102102
{
103-
// This is optional (with no default value) - there's nothing to capture here, so just move on.
103+
// This is optional (with no default value)
104+
// - there's nothing to capture here, so just move on.
104105
}
105106
else
106107
{
@@ -120,7 +121,7 @@ public IDictionary<string, object> Match(string requestPath, IDictionary<string,
120121
}
121122
}
122123

123-
for (int i = requestSegments.Length; i < Template.Segments.Count; i++)
124+
for (var i = requestSegments.Length; i < Template.Segments.Count; i++)
124125
{
125126
// We've matched the request path so far, but still have remaining route segments. These need
126127
// to be all single-part parameter segments with default values or else they won't match.
@@ -131,7 +132,6 @@ public IDictionary<string, object> Match(string requestPath, IDictionary<string,
131132
return null;
132133
}
133134

134-
135135
var part = routeSegment.Parts[0];
136136
if (part.IsLiteral)
137137
{
@@ -172,21 +172,24 @@ public IDictionary<string, object> Match(string requestPath, IDictionary<string,
172172
return values;
173173
}
174174

175-
private bool MatchComplexSegment(TemplateSegment routeSegment, string requestSegment, IDictionary<string, object> defaults, Dictionary<string, object> values)
175+
private bool MatchComplexSegment(TemplateSegment routeSegment,
176+
string requestSegment,
177+
IDictionary<string, object> defaults,
178+
Dictionary<string, object> values)
176179
{
177180
Contract.Assert(routeSegment != null);
178181
Contract.Assert(routeSegment.Parts.Count > 1);
179182

180183
// Find last literal segment and get its last index in the string
181-
int lastIndex = requestSegment.Length;
182-
int indexOfLastSegmentUsed = routeSegment.Parts.Count - 1;
184+
var lastIndex = requestSegment.Length;
185+
var indexOfLastSegmentUsed = routeSegment.Parts.Count - 1;
183186

184187
TemplatePart parameterNeedsValue = null; // Keeps track of a parameter segment that is pending a value
185188
TemplatePart lastLiteral = null; // Keeps track of the left-most literal we've encountered
186189

187190
while (indexOfLastSegmentUsed >= 0)
188191
{
189-
int newLastIndex = lastIndex;
192+
var newLastIndex = lastIndex;
190193

191194
var part = routeSegment.Parts[indexOfLastSegmentUsed];
192195
if (part.IsParameter)
@@ -199,7 +202,7 @@ private bool MatchComplexSegment(TemplateSegment routeSegment, string requestSeg
199202
Contract.Assert(part.IsLiteral);
200203
lastLiteral = part;
201204

202-
int startIndex = lastIndex - 1;
205+
var startIndex = lastIndex - 1;
203206
// If we have a pending parameter subsegment, we must leave at least one character for that
204207
if (parameterNeedsValue != null)
205208
{
@@ -211,7 +214,9 @@ private bool MatchComplexSegment(TemplateSegment routeSegment, string requestSeg
211214
return false;
212215
}
213216

214-
int indexOfLiteral = requestSegment.LastIndexOf(part.Text, startIndex, StringComparison.OrdinalIgnoreCase);
217+
var indexOfLiteral = requestSegment.LastIndexOf(part.Text,
218+
startIndex,
219+
StringComparison.OrdinalIgnoreCase);
215220
if (indexOfLiteral == -1)
216221
{
217222
// If we couldn't find this literal index, this segment cannot match
@@ -232,7 +237,8 @@ private bool MatchComplexSegment(TemplateSegment routeSegment, string requestSeg
232237
newLastIndex = indexOfLiteral;
233238
}
234239

235-
if ((parameterNeedsValue != null) && (((lastLiteral != null) && (part.IsLiteral)) || (indexOfLastSegmentUsed == 0)))
240+
if ((parameterNeedsValue != null) &&
241+
(((lastLiteral != null) && (part.IsLiteral)) || (indexOfLastSegmentUsed == 0)))
236242
{
237243
// If we have a pending parameter that needs a value, grab that value
238244

@@ -267,7 +273,7 @@ private bool MatchComplexSegment(TemplateSegment routeSegment, string requestSeg
267273
}
268274
}
269275

270-
string parameterValueString = requestSegment.Substring(parameterStartIndex, parameterTextLength);
276+
var parameterValueString = requestSegment.Substring(parameterStartIndex, parameterTextLength);
271277

272278
if (string.IsNullOrEmpty(parameterValueString))
273279
{
@@ -298,6 +304,5 @@ private bool MatchComplexSegment(TemplateSegment routeSegment, string requestSeg
298304
// This check is related to the check we do earlier in this function for LiteralSubsegments.
299305
return (lastIndex == 0) || routeSegment.Parts[0].IsParameter;
300306
}
301-
302307
}
303308
}

0 commit comments

Comments
 (0)