Skip to content

Commit aa80139

Browse files
committed
use negation pattern
1 parent 7857663 commit aa80139

File tree

7 files changed

+21
-21
lines changed

7 files changed

+21
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public MapNode(ParsingContext context, string yamlString) :
3030
public MapNode(ParsingContext context, YamlNode node) : base(
3131
context)
3232
{
33-
if (!(node is YamlMappingNode mapNode))
33+
if (node is not YamlMappingNode mapNode)
3434
{
3535
throw new OpenApiReaderException("Expected map.", Context);
3636
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
5050
return newObject;
5151
}
5252

53-
if (!(openApiAny is OpenApiString))
53+
if (openApiAny is not OpenApiString)
5454
{
5555
return openApiAny;
5656
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected ParseNode(ParsingContext parsingContext)
2424

2525
public MapNode CheckMapNode(string nodeName)
2626
{
27-
if (!(this is MapNode mapNode))
27+
if (this is not MapNode mapNode)
2828
{
2929
throw new OpenApiReaderException($"{nodeName} must be a map/object", Context);
3030
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class ValueNode : ParseNode
1515
public ValueNode(ParsingContext context, YamlNode node) : base(
1616
context)
1717
{
18-
if (!(node is YamlScalarNode scalarNode))
18+
if (node is not YamlScalarNode scalarNode)
1919
{
2020
throw new OpenApiReaderException("Expected a value.", node);
2121
}

src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static void ValidateDataTypeMismatch(
7575
}
7676

7777
// If value is not a string and also not an object, there is a data mismatch.
78-
if (!(value is OpenApiObject))
78+
if (value is not OpenApiObject)
7979
{
8080
context.CreateWarning(
8181
ruleName,
@@ -115,7 +115,7 @@ public static void ValidateDataTypeMismatch(
115115
}
116116

117117
// If value is not a string and also not an array, there is a data mismatch.
118-
if (!(value is OpenApiArray))
118+
if (value is not OpenApiArray)
119119
{
120120
context.CreateWarning(
121121
ruleName,
@@ -139,7 +139,7 @@ public static void ValidateDataTypeMismatch(
139139

140140
if (type == "integer" && format == "int32")
141141
{
142-
if (!(value is OpenApiInteger))
142+
if (value is not OpenApiInteger)
143143
{
144144
context.CreateWarning(
145145
ruleName,
@@ -151,7 +151,7 @@ public static void ValidateDataTypeMismatch(
151151

152152
if (type == "integer" && format == "int64")
153153
{
154-
if (!(value is OpenApiLong))
154+
if (value is not OpenApiLong)
155155
{
156156
context.CreateWarning(
157157
ruleName,
@@ -161,9 +161,9 @@ public static void ValidateDataTypeMismatch(
161161
return;
162162
}
163163

164-
if (type == "integer" && !(value is OpenApiInteger))
164+
if (type == "integer" && value is not OpenApiInteger)
165165
{
166-
if (!(value is OpenApiInteger))
166+
if (value is not OpenApiInteger)
167167
{
168168
context.CreateWarning(
169169
ruleName,
@@ -175,7 +175,7 @@ public static void ValidateDataTypeMismatch(
175175

176176
if (type == "number" && format == "float")
177177
{
178-
if (!(value is OpenApiFloat))
178+
if (value is not OpenApiFloat)
179179
{
180180
context.CreateWarning(
181181
ruleName,
@@ -187,7 +187,7 @@ public static void ValidateDataTypeMismatch(
187187

188188
if (type == "number" && format == "double")
189189
{
190-
if (!(value is OpenApiDouble))
190+
if (value is not OpenApiDouble)
191191
{
192192
context.CreateWarning(
193193
ruleName,
@@ -199,7 +199,7 @@ public static void ValidateDataTypeMismatch(
199199

200200
if (type == "number")
201201
{
202-
if (!(value is OpenApiDouble))
202+
if (value is not OpenApiDouble)
203203
{
204204
context.CreateWarning(
205205
ruleName,
@@ -211,7 +211,7 @@ public static void ValidateDataTypeMismatch(
211211

212212
if (type == "string" && format == "byte")
213213
{
214-
if (!(value is OpenApiByte))
214+
if (value is not OpenApiByte)
215215
{
216216
context.CreateWarning(
217217
ruleName,
@@ -223,7 +223,7 @@ public static void ValidateDataTypeMismatch(
223223

224224
if (type == "string" && format == "date")
225225
{
226-
if (!(value is OpenApiDate))
226+
if (value is not OpenApiDate)
227227
{
228228
context.CreateWarning(
229229
ruleName,
@@ -235,7 +235,7 @@ public static void ValidateDataTypeMismatch(
235235

236236
if (type == "string" && format == "date-time")
237237
{
238-
if (!(value is OpenApiDateTime))
238+
if (value is not OpenApiDateTime)
239239
{
240240
context.CreateWarning(
241241
ruleName,
@@ -247,7 +247,7 @@ public static void ValidateDataTypeMismatch(
247247

248248
if (type == "string" && format == "password")
249249
{
250-
if (!(value is OpenApiPassword))
250+
if (value is not OpenApiPassword)
251251
{
252252
context.CreateWarning(
253253
ruleName,
@@ -259,7 +259,7 @@ public static void ValidateDataTypeMismatch(
259259

260260
if (type == "string")
261261
{
262-
if (!(value is OpenApiString))
262+
if (value is not OpenApiString)
263263
{
264264
context.CreateWarning(
265265
ruleName,
@@ -271,7 +271,7 @@ public static void ValidateDataTypeMismatch(
271271

272272
if (type == "boolean")
273273
{
274-
if (!(value is OpenApiBoolean))
274+
if (value is not OpenApiBoolean)
275275
{
276276
context.CreateWarning(
277277
ruleName,

src/Microsoft.OpenApi/Validations/ValidationRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ internal override void Evaluate(IValidationContext context, object item)
5959
return;
6060
}
6161

62-
if (!(item is T))
62+
if (item is not T)
6363
{
6464
throw Error.Argument(string.Format(SRResource.InputItemShouldBeType, typeof(T).FullName));
6565
}

test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static IEnumerable<object[]> GetSchemas()
6262

6363
JToken GetProp(JToken obj, string prop)
6464
{
65-
if (!(obj is JObject jObj))
65+
if (obj is not JObject jObj)
6666
return null;
6767
if (!jObj.TryGetValue(prop, out var jToken))
6868
return null;

0 commit comments

Comments
 (0)