Skip to content

Commit cf89b4f

Browse files
committed
use some pattern matiching
1 parent 7857663 commit cf89b4f

File tree

8 files changed

+16
-14
lines changed

8 files changed

+16
-14
lines changed

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,15 @@ private static async Task<Stream> GetStream(string input, ILogger logger, Cancel
510510
var fileInput = new FileInfo(input);
511511
stream = fileInput.OpenRead();
512512
}
513-
catch (Exception ex) when (ex is FileNotFoundException ||
514-
ex is PathTooLongException ||
515-
ex is DirectoryNotFoundException ||
516-
ex is IOException ||
517-
ex is UnauthorizedAccessException ||
518-
ex is SecurityException ||
519-
ex is NotSupportedException)
513+
catch (Exception ex) when (
514+
ex is
515+
FileNotFoundException or
516+
PathTooLongException or
517+
DirectoryNotFoundException or
518+
IOException or
519+
UnauthorizedAccessException or
520+
SecurityException or
521+
NotSupportedException)
520522
{
521523
throw new InvalidOperationException($"Could not open the file at {input}", ex);
522524
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
116116
return openApiAny;
117117
}
118118

119-
if (value == null || value == "null")
119+
if (value is null or "null")
120120
{
121121
return new OpenApiNull();
122122
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override string GetScalarValue()
3434
public override IOpenApiAny CreateAny()
3535
{
3636
var value = GetScalarValue();
37-
return new OpenApiString(value, this._node.Style == ScalarStyle.SingleQuoted || this._node.Style == ScalarStyle.DoubleQuoted || this._node.Style == ScalarStyle.Literal || this._node.Style == ScalarStyle.Folded);
37+
return new OpenApiString(value, this._node.Style is ScalarStyle.SingleQuoted or ScalarStyle.DoubleQuoted or ScalarStyle.Literal or ScalarStyle.Folded);
3838
}
3939
}
4040
}

src/Microsoft.OpenApi.Readers/ParsingContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal OpenApiDocument Parse(YamlDocument yamlDocument)
6060

6161
switch (inputVersion)
6262
{
63-
case string version when version == "2.0":
63+
case string and "2.0":
6464
VersionService = new OpenApiV2VersionService(Diagnostic);
6565
doc = VersionService.LoadDocument(RootNode);
6666
this.Diagnostic.SpecificationVersion = OpenApiSpecVersion.OpenApi2_0;

src/Microsoft.OpenApi.Readers/V2/OpenApiV2VersionService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public OpenApiReference ConvertToOpenApiReference(string reference, ReferenceTyp
152152
};
153153
}
154154

155-
if (type == ReferenceType.Tag || type == ReferenceType.SecurityScheme)
155+
if (type is ReferenceType.Tag or ReferenceType.SecurityScheme)
156156
{
157157
return new OpenApiReference
158158
{

src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public OpenApiReference ConvertToOpenApiReference(
7878
var segments = reference.Split('#');
7979
if (segments.Length == 1)
8080
{
81-
if (type == ReferenceType.Tag || type == ReferenceType.SecurityScheme)
81+
if (type is ReferenceType.Tag or ReferenceType.SecurityScheme)
8282
{
8383
return new OpenApiReference
8484
{

src/Microsoft.OpenApi/MicrosoftExtensions/OpenApiEnumValuesDescriptionExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class OpenApiEnumValuesDescriptionExtension : IOpenApiExtension
3838
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
3939
{
4040
if (writer is null) throw new ArgumentNullException(nameof(writer));
41-
if ((specVersion == OpenApiSpecVersion.OpenApi2_0 || specVersion == OpenApiSpecVersion.OpenApi3_0) &&
41+
if (specVersion is OpenApiSpecVersion.OpenApi2_0 or OpenApiSpecVersion.OpenApi3_0 &&
4242
!string.IsNullOrEmpty(EnumName) &&
4343
ValuesDescriptions.Any())
4444
{ // when we upgrade to 3.1, we don't need to write this extension as JSON schema will support writing enum values

test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterAnyExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private static string WriteAsJson(IOpenApiAny any, bool produceTerseOutput = fal
274274
// Act
275275
var value = new StreamReader(stream).ReadToEnd();
276276

277-
if (any.AnyType == AnyType.Primitive || any.AnyType == AnyType.Null)
277+
if (any.AnyType is AnyType.Primitive or AnyType.Null)
278278
{
279279
return value;
280280
}

0 commit comments

Comments
 (0)