Skip to content

Commit

Permalink
Fix #387 - wrong field inferencing in yaml to json (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
akarboush authored Feb 18, 2022
1 parent 558163d commit 7cfa974
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
using System;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;

Expand All @@ -13,9 +14,9 @@ public bool Resolve(NodeEvent? nodeEvent, ref Type currentType)
{
// avoid unnecessary parsing attempts
bool couldBeNumber =
(scalar.Style is not ScalarStyle.SingleQuoted and not ScalarStyle.DoubleQuoted) &&
scalar.Value.Length != 0 &&
(scalar.Value[0] is >= '0' and <= '9' ||
scalar.Value[0] == '-');
(scalar.Value[0] is >= '0' and <= '9' || scalar.Value[0] == '-');

if (couldBeNumber && decimal.TryParse(scalar.Value, out _))
{
Expand Down

0 comments on commit 7cfa974

Please sign in to comment.