From 42914d93ca8375ba089ee4ae5f1e48967f3b63f1 Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Sun, 21 Oct 2018 03:05:05 +0200 Subject: [PATCH] Declare out variables inline, and use discards (#873) --- .../DecisionTreeBuilder.cs | 6 ++---- .../Constraints/BoolRouteConstraint.cs | 6 ++---- .../Constraints/DateTimeRouteConstraint.cs | 6 ++---- .../Constraints/DecimalRouteConstraint.cs | 6 ++---- .../Constraints/DoubleRouteConstraint.cs | 6 ++---- .../Constraints/FloatRouteConstraint.cs | 6 ++---- .../Constraints/GuidRouteConstraint.cs | 6 ++---- .../Constraints/HttpMethodRouteConstraint.cs | 3 +-- .../Constraints/IntRouteConstraint.cs | 6 ++---- .../Constraints/LengthRouteConstraint.cs | 3 +-- .../Constraints/LongRouteConstraint.cs | 6 ++---- .../Constraints/MaxLengthRouteConstraint.cs | 3 +-- .../Constraints/MaxRouteConstraint.cs | 6 ++---- .../Constraints/MinLengthRouteConstraint.cs | 3 +-- .../Constraints/MinRouteConstraint.cs | 6 ++---- .../Constraints/OptionalRouteConstraint.cs | 3 +-- .../Constraints/RangeRouteConstraint.cs | 6 ++---- .../Constraints/RegexRouteConstraint.cs | 4 +--- .../Constraints/RequiredRouteConstraint.cs | 3 +-- .../Constraints/StringRouteConstraint.cs | 4 +--- .../Internal/LinkGenerationDecisionTree.cs | 6 ++---- src/Microsoft.AspNetCore.Routing/RouteCollection.cs | 4 ++-- src/Microsoft.AspNetCore.Routing/RouteConstraintBuilder.cs | 3 +-- src/Microsoft.AspNetCore.Routing/RouteConstraintMatcher.cs | 3 +-- .../Template/TemplateMatcher.cs | 3 +-- src/Microsoft.AspNetCore.Routing/Tree/TreeEnumerator.cs | 3 +-- src/Microsoft.AspNetCore.Routing/Tree/TreeRouteBuilder.cs | 3 +-- src/Microsoft.AspNetCore.Routing/Tree/TreeRouter.cs | 6 ++---- src/Microsoft.AspNetCore.Routing/Tree/UrlMatchingTree.cs | 3 +-- 29 files changed, 44 insertions(+), 88 deletions(-) diff --git a/shared/Microsoft.AspNetCore.Routing.DecisionTree.Sources/DecisionTreeBuilder.cs b/shared/Microsoft.AspNetCore.Routing.DecisionTree.Sources/DecisionTreeBuilder.cs index c4a48f5cce..293ce4aa46 100644 --- a/shared/Microsoft.AspNetCore.Routing.DecisionTree.Sources/DecisionTreeBuilder.cs +++ b/shared/Microsoft.AspNetCore.Routing.DecisionTree.Sources/DecisionTreeBuilder.cs @@ -125,15 +125,13 @@ namespace Microsoft.AspNetCore.Routing.DecisionTree unsatisfiedCriteria++; - Criterion criterion; - if (!criteria.TryGetValue(kvp.Key, out criterion)) + if (!criteria.TryGetValue(kvp.Key, out var criterion)) { criterion = new Criterion(comparer); criteria.Add(kvp.Key, criterion); } - List> branch; - if (!criterion.TryGetValue(kvp.Value, out branch)) + if (!criterion.TryGetValue(kvp.Value, out var branch)) { branch = new List>(); criterion.Add(kvp.Value, branch); diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/BoolRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/BoolRouteConstraint.cs index c91f7305a4..d19000f9de 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/BoolRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/BoolRouteConstraint.cs @@ -30,17 +30,15 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { if (value is bool) { return true; } - bool result; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); - return bool.TryParse(valueString, out result); + return bool.TryParse(valueString, out _); } return false; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/DateTimeRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/DateTimeRouteConstraint.cs index 9105108d00..a912a84f52 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/DateTimeRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/DateTimeRouteConstraint.cs @@ -36,17 +36,15 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { if (value is DateTime) { return true; } - DateTime result; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); - return DateTime.TryParse(valueString, CultureInfo.InvariantCulture, DateTimeStyles.None, out result); + return DateTime.TryParse(valueString, CultureInfo.InvariantCulture, DateTimeStyles.None, out _); } return false; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/DecimalRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/DecimalRouteConstraint.cs index 808d448706..9fcc80a9f1 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/DecimalRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/DecimalRouteConstraint.cs @@ -30,17 +30,15 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { if (value is decimal) { return true; } - decimal result; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); - return decimal.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out result); + return decimal.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out _); } return false; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/DoubleRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/DoubleRouteConstraint.cs index 0a8064f468..405e46cb0d 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/DoubleRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/DoubleRouteConstraint.cs @@ -30,21 +30,19 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { if (value is double) { return true; } - double result; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); return double.TryParse( valueString, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, - out result); + out _); } return false; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/FloatRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/FloatRouteConstraint.cs index eff69c8ad1..fbdd3c87d6 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/FloatRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/FloatRouteConstraint.cs @@ -30,21 +30,19 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { if (value is float) { return true; } - float result; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); return float.TryParse( valueString, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, - out result); + out _); } return false; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/GuidRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/GuidRouteConstraint.cs index aa1c74ec07..b87069df98 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/GuidRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/GuidRouteConstraint.cs @@ -32,17 +32,15 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { if (value is Guid) { return true; } - Guid result; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); - return Guid.TryParse(valueString, out result); + return Guid.TryParse(valueString, out _); } return false; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/HttpMethodRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/HttpMethodRouteConstraint.cs index f5a4d81830..18fbec0c19 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/HttpMethodRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/HttpMethodRouteConstraint.cs @@ -76,8 +76,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints // signal that he is generating a URI that will be used for an HTTP POST, so he wants the URI // generation to be performed by the (b) route instead of the (a) route, consistent with what would // happen on incoming requests. - object obj; - if (!values.TryGetValue(routeKey, out obj)) + if (!values.TryGetValue(routeKey, out var obj)) { return true; } diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/IntRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/IntRouteConstraint.cs index 82f32052ee..34ff02331e 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/IntRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/IntRouteConstraint.cs @@ -30,17 +30,15 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { if (value is int) { return true; } - int result; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); - return int.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); + return int.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out _); } return false; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/LengthRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/LengthRouteConstraint.cs index f102af6ec4..8964f2549e 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/LengthRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/LengthRouteConstraint.cs @@ -87,8 +87,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); var length = valueString.Length; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/LongRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/LongRouteConstraint.cs index 6d12c74d79..8ed5cccc46 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/LongRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/LongRouteConstraint.cs @@ -30,17 +30,15 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { if (value is long) { return true; } - long result; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); - return long.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out result); + return long.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out _); } return false; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/MaxLengthRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/MaxLengthRouteConstraint.cs index a7858477da..4005a041aa 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/MaxLengthRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/MaxLengthRouteConstraint.cs @@ -50,8 +50,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); return valueString.Length <= MaxLength; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/MaxRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/MaxRouteConstraint.cs index f20cce6c6c..dab22f5075 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/MaxRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/MaxRouteConstraint.cs @@ -44,12 +44,10 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { - long longValue; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); - if (long.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out longValue)) + if (long.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var longValue)) { return longValue <= Max; } diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/MinLengthRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/MinLengthRouteConstraint.cs index 7a51bf7412..c58bd0b30d 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/MinLengthRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/MinLengthRouteConstraint.cs @@ -50,8 +50,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); return valueString.Length >= MinLength; diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/MinRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/MinRouteConstraint.cs index 701d5c68e8..450ed46fbf 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/MinRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/MinRouteConstraint.cs @@ -44,12 +44,10 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { - long longValue; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); - if (long.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out longValue)) + if (long.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var longValue)) { return longValue >= Min; } diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/OptionalRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/OptionalRouteConstraint.cs index 9a9cca8e42..6b7cf8a1a5 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/OptionalRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/OptionalRouteConstraint.cs @@ -40,8 +40,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value)) + if (values.TryGetValue(routeKey, out var value)) { return InnerConstraint.Match(httpContext, route, diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/RangeRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/RangeRouteConstraint.cs index cc2487cfcb..34c946fa66 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/RangeRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/RangeRouteConstraint.cs @@ -58,12 +58,10 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { - long longValue; var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); - if (Int64.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out longValue)) + if (long.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var longValue)) { return longValue >= Min && longValue <= Max; } diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/RegexRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/RegexRouteConstraint.cs index c4e83f40e3..9269de51a3 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/RegexRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/RegexRouteConstraint.cs @@ -54,9 +54,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object routeValue; - - if (values.TryGetValue(routeKey, out routeValue) + if (values.TryGetValue(routeKey, out var routeValue) && routeValue != null) { var parameterValueString = Convert.ToString(routeValue, CultureInfo.InvariantCulture); diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/RequiredRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/RequiredRouteConstraint.cs index 827f85ea39..e33e1e23a6 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/RequiredRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/RequiredRouteConstraint.cs @@ -34,8 +34,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object value; - if (values.TryGetValue(routeKey, out value) && value != null) + if (values.TryGetValue(routeKey, out var value) && value != null) { // In routing the empty string is equivalent to null, which is equivalent to an unset value. var valueString = Convert.ToString(value, CultureInfo.InvariantCulture); diff --git a/src/Microsoft.AspNetCore.Routing/Constraints/StringRouteConstraint.cs b/src/Microsoft.AspNetCore.Routing/Constraints/StringRouteConstraint.cs index 20103058a7..fb6a3568c3 100644 --- a/src/Microsoft.AspNetCore.Routing/Constraints/StringRouteConstraint.cs +++ b/src/Microsoft.AspNetCore.Routing/Constraints/StringRouteConstraint.cs @@ -41,9 +41,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints throw new ArgumentNullException(nameof(values)); } - object routeValue; - - if (values.TryGetValue(routeKey, out routeValue) + if (values.TryGetValue(routeKey, out var routeValue) && routeValue != null) { var parameterValueString = Convert.ToString(routeValue, CultureInfo.InvariantCulture); diff --git a/src/Microsoft.AspNetCore.Routing/Internal/LinkGenerationDecisionTree.cs b/src/Microsoft.AspNetCore.Routing/Internal/LinkGenerationDecisionTree.cs index f276bf0658..61a4cd1960 100644 --- a/src/Microsoft.AspNetCore.Routing/Internal/LinkGenerationDecisionTree.cs +++ b/src/Microsoft.AspNetCore.Routing/Internal/LinkGenerationDecisionTree.cs @@ -87,11 +87,9 @@ namespace Microsoft.AspNetCore.Routing.Internal var criterion = node.Criteria[i]; var key = criterion.Key; - object value; - if (values.TryGetValue(key, out value)) + if (values.TryGetValue(key, out var value)) { - DecisionTreeNode branch; - if (criterion.Branches.TryGetValue(value ?? string.Empty, out branch)) + if (criterion.Branches.TryGetValue(value ?? string.Empty, out var branch)) { Walk(results, values, ambientValues, branch, isFallbackPath); } diff --git a/src/Microsoft.AspNetCore.Routing/RouteCollection.cs b/src/Microsoft.AspNetCore.Routing/RouteCollection.cs index 512107274e..555fdd63ae 100644 --- a/src/Microsoft.AspNetCore.Routing/RouteCollection.cs +++ b/src/Microsoft.AspNetCore.Routing/RouteCollection.cs @@ -91,8 +91,8 @@ namespace Microsoft.AspNetCore.Routing if (!string.IsNullOrEmpty(context.RouteName)) { VirtualPathData namedRoutePathData = null; - INamedRouter matchedNamedRoute; - if (_namedRoutes.TryGetValue(context.RouteName, out matchedNamedRoute)) + + if (_namedRoutes.TryGetValue(context.RouteName, out var matchedNamedRoute)) { namedRoutePathData = matchedNamedRoute.GetVirtualPath(context); } diff --git a/src/Microsoft.AspNetCore.Routing/RouteConstraintBuilder.cs b/src/Microsoft.AspNetCore.Routing/RouteConstraintBuilder.cs index 0c444236a5..5bb40282a6 100644 --- a/src/Microsoft.AspNetCore.Routing/RouteConstraintBuilder.cs +++ b/src/Microsoft.AspNetCore.Routing/RouteConstraintBuilder.cs @@ -184,8 +184,7 @@ namespace Microsoft.AspNetCore.Routing private void Add(string key, IRouteConstraint constraint) { - List list; - if (!_constraints.TryGetValue(key, out list)) + if (!_constraints.TryGetValue(key, out var list)) { list = new List(); _constraints.Add(key, list); diff --git a/src/Microsoft.AspNetCore.Routing/RouteConstraintMatcher.cs b/src/Microsoft.AspNetCore.Routing/RouteConstraintMatcher.cs index 8601d85581..d19a743fad 100644 --- a/src/Microsoft.AspNetCore.Routing/RouteConstraintMatcher.cs +++ b/src/Microsoft.AspNetCore.Routing/RouteConstraintMatcher.cs @@ -51,8 +51,7 @@ namespace Microsoft.AspNetCore.Routing { if (routeDirection.Equals(RouteDirection.IncomingRequest)) { - object routeValue; - routeValues.TryGetValue(kvp.Key, out routeValue); + routeValues.TryGetValue(kvp.Key, out var routeValue); logger.RouteValueDoesNotMatchConstraint(routeValue, kvp.Key, kvp.Value); } diff --git a/src/Microsoft.AspNetCore.Routing/Template/TemplateMatcher.cs b/src/Microsoft.AspNetCore.Routing/Template/TemplateMatcher.cs index ebb0a0d779..31bb97d394 100644 --- a/src/Microsoft.AspNetCore.Routing/Template/TemplateMatcher.cs +++ b/src/Microsoft.AspNetCore.Routing/Template/TemplateMatcher.cs @@ -49,8 +49,7 @@ namespace Microsoft.AspNetCore.Routing.Template continue; } - object value; - if (Defaults.TryGetValue(part.Name, out value)) + if (Defaults.TryGetValue(part.Name, out var value)) { _hasDefaultValue[i] = true; _defaultValues[i] = value; diff --git a/src/Microsoft.AspNetCore.Routing/Tree/TreeEnumerator.cs b/src/Microsoft.AspNetCore.Routing/Tree/TreeEnumerator.cs index db59b0a396..cdd7ec6f81 100644 --- a/src/Microsoft.AspNetCore.Routing/Tree/TreeEnumerator.cs +++ b/src/Microsoft.AspNetCore.Routing/Tree/TreeEnumerator.cs @@ -91,9 +91,8 @@ namespace Microsoft.AspNetCore.Routing.Tree if (next.Literals.Count > 0) { - UrlMatchingNode node; Debug.Assert(next.Depth < _tokenizer.Count); - if (next.Literals.TryGetValue(_tokenizer[next.Depth].Value, out node)) + if (next.Literals.TryGetValue(_tokenizer[next.Depth].Value, out var node)) { _stack.Push(node); } diff --git a/src/Microsoft.AspNetCore.Routing/Tree/TreeRouteBuilder.cs b/src/Microsoft.AspNetCore.Routing/Tree/TreeRouteBuilder.cs index 400424f4c1..f796328a82 100644 --- a/src/Microsoft.AspNetCore.Routing/Tree/TreeRouteBuilder.cs +++ b/src/Microsoft.AspNetCore.Routing/Tree/TreeRouteBuilder.cs @@ -259,8 +259,7 @@ namespace Microsoft.AspNetCore.Routing.Tree foreach (var entry in InboundEntries) { - UrlMatchingTree tree; - if (!trees.TryGetValue(entry.Order, out tree)) + if (!trees.TryGetValue(entry.Order, out var tree)) { tree = new UrlMatchingTree(entry.Order); trees.Add(entry.Order, tree); diff --git a/src/Microsoft.AspNetCore.Routing/Tree/TreeRouter.cs b/src/Microsoft.AspNetCore.Routing/Tree/TreeRouter.cs index 8670b6cdff..3f98325641 100644 --- a/src/Microsoft.AspNetCore.Routing/Tree/TreeRouter.cs +++ b/src/Microsoft.AspNetCore.Routing/Tree/TreeRouter.cs @@ -103,8 +103,7 @@ namespace Microsoft.AspNetCore.Routing.Tree // We only need to keep one OutboundMatch per route template // so in case two entries have the same name and the same template we only keep // the first entry. - OutboundMatch namedMatch; - if (_namedEntries.TryGetValue(entry.RouteName, out namedMatch) && + if (_namedEntries.TryGetValue(entry.RouteName, out var namedMatch) && !string.Equals( namedMatch.Entry.RouteTemplate.TemplateText, entry.RouteTemplate.TemplateText, @@ -233,8 +232,7 @@ namespace Microsoft.AspNetCore.Routing.Tree private VirtualPathData GetVirtualPathForNamedRoute(VirtualPathContext context) { - OutboundMatch match; - if (_namedEntries.TryGetValue(context.RouteName, out match)) + if (_namedEntries.TryGetValue(context.RouteName, out var match)) { var path = GenerateVirtualPath(context, match.Entry, match.TemplateBinder); if (path != null) diff --git a/src/Microsoft.AspNetCore.Routing/Tree/UrlMatchingTree.cs b/src/Microsoft.AspNetCore.Routing/Tree/UrlMatchingTree.cs index 96e6940653..570dce1b3a 100644 --- a/src/Microsoft.AspNetCore.Routing/Tree/UrlMatchingTree.cs +++ b/src/Microsoft.AspNetCore.Routing/Tree/UrlMatchingTree.cs @@ -86,8 +86,7 @@ namespace Microsoft.AspNetCore.Routing.Tree var part = segment.Parts[0]; if (part.IsLiteral) { - UrlMatchingNode next; - if (!current.Literals.TryGetValue(part.Text, out next)) + if (!current.Literals.TryGetValue(part.Text, out var next)) { next = new UrlMatchingNode(length: i + 1); current.Literals.Add(part.Text, next);