Skip to content

Commit 9aa7897

Browse files
committed
inline some out variables
1 parent 7857663 commit 9aa7897

File tree

8 files changed

+13
-27
lines changed

8 files changed

+13
-27
lines changed

src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public PropertyNode this[string key]
4747
{
4848
get
4949
{
50-
YamlNode node;
51-
if (this._node.Children.TryGetValue(new YamlScalarNode(key), out node))
50+
if (this._node.Children.TryGetValue(new YamlScalarNode(key), out var node))
5251
{
5352
return new PropertyNode(Context, key, node);
5453
}
@@ -193,9 +192,7 @@ public T GetReferencedObject<T>(ReferenceType referenceType, string referenceId)
193192

194193
public string GetReferencePointer()
195194
{
196-
YamlNode refNode;
197-
198-
if (!_node.Children.TryGetValue(new YamlScalarNode("$ref"), out refNode))
195+
if (!_node.Children.TryGetValue(new YamlScalarNode("$ref"), out var refNode))
199196
{
200197
return null;
201198
}

src/Microsoft.OpenApi.Readers/ParseNodes/PropertyNode.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public void ParseField<T>(
3030
IDictionary<string, Action<T, ParseNode>> fixedFields,
3131
IDictionary<Func<string, bool>, Action<T, string, ParseNode>> patternFields)
3232
{
33-
Action<T, ParseNode> fixedFieldMap;
34-
var found = fixedFields.TryGetValue(Name, out fixedFieldMap);
33+
var found = fixedFields.TryGetValue(Name, out var fixedFieldMap);
3534

3635
if (fixedFieldMap != null)
3736
{

src/Microsoft.OpenApi.Readers/ParsingContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ public void StartObject(string objectName)
206206
/// <returns>If method returns false a loop was detected and the key is not added.</returns>
207207
public bool PushLoop(string loopId, string key)
208208
{
209-
Stack<string> stack;
210-
if (!_loopStacks.TryGetValue(loopId, out stack))
209+
if (!_loopStacks.TryGetValue(loopId, out var stack))
211210
{
212211
stack = new Stack<string>();
213212
_loopStacks.Add(loopId, stack);

src/Microsoft.OpenApi/Services/LoopDetector.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ internal class LoopDetector
1717
/// <returns>If method returns false a loop was detected and the key is not added.</returns>
1818
public bool PushLoop<T>(T key)
1919
{
20-
Stack<object> stack;
21-
if (!_loopStacks.TryGetValue(typeof(T), out stack))
20+
if (!_loopStacks.TryGetValue(typeof(T), out var stack))
2221
{
2322
stack = new Stack<object>();
2423
_loopStacks.Add(typeof(T), stack);

src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public sealed class ValidationRuleSet : IEnumerable<ValidationRule>
3030
/// <returns>Either the rules related to the type, or an empty list.</returns>
3131
public IList<ValidationRule> FindRules(Type type)
3232
{
33-
IList<ValidationRule> results = null;
34-
_rules.TryGetValue(type, out results);
33+
_rules.TryGetValue(type, out var results);
3534
return results ?? _emptyRules;
3635
}
3736

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ public void ParseStringContactFragmentShouldSucceed()
2121
}
2222
";
2323
var reader = new OpenApiStringReader();
24-
var diagnostic = new OpenApiDiagnostic();
2524

2625
// Act
27-
var contact = reader.ReadFragment<OpenApiContact>(input, OpenApiSpecVersion.OpenApi2_0, out diagnostic);
26+
var contact = reader.ReadFragment<OpenApiContact>(input, OpenApiSpecVersion.OpenApi2_0, out var diagnostic);
2827

2928
// Assert
3029
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ public void ParseStringContactFragmentShouldSucceed()
2121
}
2222
";
2323
var reader = new OpenApiStringReader();
24-
var diagnostic = new OpenApiDiagnostic();
2524

2625
// Act
27-
var contact = reader.ReadFragment<OpenApiContact>(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic);
26+
var contact = reader.ReadFragment<OpenApiContact>(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic);
2827

2928
// Assert
3029
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ public void ParsePrimitiveSchemaFragmentShouldSucceed()
5454
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "primitiveSchema.yaml")))
5555
{
5656
var reader = new OpenApiStreamReader();
57-
var diagnostic = new OpenApiDiagnostic();
5857

5958
// Act
60-
var schema = reader.ReadFragment<OpenApiSchema>(stream, OpenApiSpecVersion.OpenApi3_0, out diagnostic);
59+
var schema = reader.ReadFragment<OpenApiSchema>(stream, OpenApiSpecVersion.OpenApi3_0, out var diagnostic);
6160

6261
// Assert
6362
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());
@@ -81,10 +80,9 @@ public void ParsePrimitiveStringSchemaFragmentShouldSucceed()
8180
}
8281
";
8382
var reader = new OpenApiStringReader();
84-
var diagnostic = new OpenApiDiagnostic();
8583

8684
// Act
87-
var schema = reader.ReadFragment<OpenApiSchema>(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic);
85+
var schema = reader.ReadFragment<OpenApiSchema>(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic);
8886

8987
// Assert
9088
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());
@@ -107,10 +105,9 @@ public void ParseExampleStringFragmentShouldSucceed()
107105
""baz"": [ 1,2]
108106
}";
109107
var reader = new OpenApiStringReader();
110-
var diagnostic = new OpenApiDiagnostic();
111108

112109
// Act
113-
var openApiAny = reader.ReadFragment<IOpenApiAny>(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic);
110+
var openApiAny = reader.ReadFragment<IOpenApiAny>(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic);
114111

115112
// Assert
116113
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());
@@ -135,10 +132,9 @@ public void ParseEnumFragmentShouldSucceed()
135132
""baz""
136133
]";
137134
var reader = new OpenApiStringReader();
138-
var diagnostic = new OpenApiDiagnostic();
139135

140136
// Act
141-
var openApiAny = reader.ReadFragment<IOpenApiAny>(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic);
137+
var openApiAny = reader.ReadFragment<IOpenApiAny>(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic);
142138

143139
// Assert
144140
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());
@@ -212,10 +208,9 @@ public void ParsePathFragmentShouldSucceed()
212208
description: Ok
213209
";
214210
var reader = new OpenApiStringReader();
215-
var diagnostic = new OpenApiDiagnostic();
216211

217212
// Act
218-
var openApiAny = reader.ReadFragment<OpenApiPathItem>(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic);
213+
var openApiAny = reader.ReadFragment<OpenApiPathItem>(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic);
219214

220215
// Assert
221216
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());

0 commit comments

Comments
 (0)