Skip to content

Commit 60b72fc

Browse files
authored
Merge pull request #1373 from SimonCropp/use-negation-pattern
use negation pattern
2 parents b1ee58c + 26f52f5 commit 60b72fc

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
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/ParseNode.cs

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

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

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: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static void ValidateDataTypeMismatch(
135135

136136
if (type == "integer" && format == "int32")
137137
{
138-
if (!(value is OpenApiInteger))
138+
if (value is not OpenApiInteger)
139139
{
140140
context.CreateWarning(
141141
ruleName,
@@ -147,7 +147,7 @@ public static void ValidateDataTypeMismatch(
147147

148148
if (type == "integer" && format == "int64")
149149
{
150-
if (!(value is OpenApiLong))
150+
if (value is not OpenApiLong)
151151
{
152152
context.CreateWarning(
153153
ruleName,
@@ -157,9 +157,9 @@ public static void ValidateDataTypeMismatch(
157157
return;
158158
}
159159

160-
if (type == "integer" && !(value is OpenApiInteger))
160+
if (type == "integer" && value is not OpenApiInteger)
161161
{
162-
if (!(value is OpenApiInteger))
162+
if (value is not OpenApiInteger)
163163
{
164164
context.CreateWarning(
165165
ruleName,
@@ -171,7 +171,7 @@ public static void ValidateDataTypeMismatch(
171171

172172
if (type == "number" && format == "float")
173173
{
174-
if (!(value is OpenApiFloat))
174+
if (value is not OpenApiFloat)
175175
{
176176
context.CreateWarning(
177177
ruleName,
@@ -183,7 +183,7 @@ public static void ValidateDataTypeMismatch(
183183

184184
if (type == "number" && format == "double")
185185
{
186-
if (!(value is OpenApiDouble))
186+
if (value is not OpenApiDouble)
187187
{
188188
context.CreateWarning(
189189
ruleName,
@@ -195,7 +195,7 @@ public static void ValidateDataTypeMismatch(
195195

196196
if (type == "number")
197197
{
198-
if (!(value is OpenApiDouble))
198+
if (value is not OpenApiDouble)
199199
{
200200
context.CreateWarning(
201201
ruleName,
@@ -207,7 +207,7 @@ public static void ValidateDataTypeMismatch(
207207

208208
if (type == "string" && format == "byte")
209209
{
210-
if (!(value is OpenApiByte))
210+
if (value is not OpenApiByte)
211211
{
212212
context.CreateWarning(
213213
ruleName,
@@ -219,7 +219,7 @@ public static void ValidateDataTypeMismatch(
219219

220220
if (type == "string" && format == "date")
221221
{
222-
if (!(value is OpenApiDate))
222+
if (value is not OpenApiDate)
223223
{
224224
context.CreateWarning(
225225
ruleName,
@@ -231,7 +231,7 @@ public static void ValidateDataTypeMismatch(
231231

232232
if (type == "string" && format == "date-time")
233233
{
234-
if (!(value is OpenApiDateTime))
234+
if (value is not OpenApiDateTime)
235235
{
236236
context.CreateWarning(
237237
ruleName,
@@ -243,7 +243,7 @@ public static void ValidateDataTypeMismatch(
243243

244244
if (type == "string" && format == "password")
245245
{
246-
if (!(value is OpenApiPassword))
246+
if (value is not OpenApiPassword)
247247
{
248248
context.CreateWarning(
249249
ruleName,
@@ -255,7 +255,7 @@ public static void ValidateDataTypeMismatch(
255255

256256
if (type == "string")
257257
{
258-
if (!(value is OpenApiString))
258+
if (value is not OpenApiString)
259259
{
260260
context.CreateWarning(
261261
ruleName,
@@ -267,7 +267,7 @@ public static void ValidateDataTypeMismatch(
267267

268268
if (type == "boolean")
269269
{
270-
if (!(value is OpenApiBoolean))
270+
if (value is not OpenApiBoolean)
271271
{
272272
context.CreateWarning(
273273
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
@@ -61,7 +61,7 @@ public static IEnumerable<object[]> GetSchemas()
6161

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

0 commit comments

Comments
 (0)