Skip to content

Commit f2ccf5b

Browse files
committed
Use pattern matching and simplify condition
1 parent 0bd881b commit f2ccf5b

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,13 @@ public static JsonNode Find(this JsonPointer currentPointer, JsonNode baseJsonNo
2929
{
3030
var array = pointer as JsonArray;
3131

32-
if (array != null)
32+
if (array != null && int.TryParse(token, out var tokenValue))
3333
{
34-
pointer = array[Convert.ToInt32(token)];
34+
pointer = array[tokenValue];
3535
}
36-
else
36+
else if(pointer is JsonObject map && !map.TryGetPropertyValue(token, out pointer))
3737
{
38-
var map = pointer as JsonObject;
39-
if (map != null)
40-
{
41-
if (!map.TryGetPropertyValue(token, out pointer))
42-
{
43-
return null;
44-
}
45-
}
38+
return null;
4639
}
4740
}
4841

0 commit comments

Comments
 (0)