@@ -18,7 +18,7 @@ public static class YamlConverter
1818        /// </summary> 
1919        /// <param name="yaml">The YAML stream.</param> 
2020        /// <returns>A collection of nodes representing the YAML documents in the stream.</returns> 
21-         public  static IEnumerable < JsonNode >  ToJsonNode ( this  YamlStream  yaml ) 
21+         public  static IEnumerable < JsonNode ? >  ToJsonNode ( this  YamlStream  yaml ) 
2222        { 
2323            return  yaml . Documents . Select ( x =>  x . ToJsonNode ( ) ) ; 
2424        } 
@@ -28,7 +28,7 @@ public static IEnumerable<JsonNode> ToJsonNode(this YamlStream yaml)
2828        /// </summary> 
2929        /// <param name="yaml">The YAML document.</param> 
3030        /// <returns>A `JsonNode` representative of the YAML document.</returns> 
31-         public  static JsonNode  ToJsonNode ( this  YamlDocument  yaml ) 
31+         public  static JsonNode ?  ToJsonNode ( this  YamlDocument  yaml ) 
3232        { 
3333            return  yaml . RootNode . ToJsonNode ( ) ; 
3434        } 
@@ -39,7 +39,7 @@ public static JsonNode ToJsonNode(this YamlDocument yaml)
3939        /// <param name="yaml">The YAML node.</param> 
4040        /// <returns>A `JsonNode` representative of the YAML node.</returns> 
4141        /// <exception cref="NotSupportedException">Thrown for YAML that is not compatible with JSON.</exception> 
42-         public  static JsonNode  ToJsonNode ( this  YamlNode  yaml ) 
42+         public  static JsonNode ?  ToJsonNode ( this  YamlNode  yaml ) 
4343        { 
4444            return  yaml  switch 
4545            { 
@@ -110,25 +110,25 @@ private static YamlSequenceNode ToYamlSequence(this JsonArray arr)
110110            return  new  YamlSequenceNode ( arr . Select ( x =>  x ! . ToYamlNode ( ) ) ) ; 
111111        } 
112112
113-         private  static JsonValue   ToJsonValue ( this   YamlScalarNode   yaml ) 
113+         private  static readonly   HashSet < string >   YamlNullRepresentations   =   new ( StringComparer . Ordinal ) 
114114        { 
115-             switch  ( yaml . Style ) 
115+             "~" , 
116+             "null" , 
117+             "Null" , 
118+             "NULL" 
119+         } ; 
120+ 
121+         private  static JsonValue ?  ToJsonValue ( this  YamlScalarNode  yaml ) 
122+         { 
123+             return  yaml . Style  switch 
116124            { 
117-                 case  ScalarStyle . Plain : 
118-                     return  decimal . TryParse ( yaml . Value ,  NumberStyles . Float ,  CultureInfo . InvariantCulture ,  out  var  d ) 
119-                         ?  JsonValue . Create ( d ) 
120-                         :  bool . TryParse ( yaml . Value ,  out  var  b ) 
121-                             ?  JsonValue . Create ( b ) 
122-                             :  JsonValue . Create ( yaml . Value ) ! ; 
123-                 case  ScalarStyle . SingleQuoted : 
124-                 case  ScalarStyle . DoubleQuoted : 
125-                 case  ScalarStyle . Literal : 
126-                 case  ScalarStyle . Folded : 
127-                 case  ScalarStyle . Any : 
128-                     return  JsonValue . Create ( yaml . Value ) ! ; 
129-                 default : 
130-                     throw  new  ArgumentOutOfRangeException ( ) ; 
131-             } 
125+                 ScalarStyle . Plain  when  decimal . TryParse ( yaml . Value ,  NumberStyles . Float ,  CultureInfo . InvariantCulture ,  out  var  d )  =>  JsonValue . Create ( d ) , 
126+                 ScalarStyle . Plain  when  bool . TryParse ( yaml . Value ,  out  var  b )  =>  JsonValue . Create ( b ) , 
127+                 ScalarStyle . Plain  when  YamlNullRepresentations . Contains ( yaml . Value )  =>  null , 
128+                 ScalarStyle . Plain  =>  JsonValue . Create ( yaml . Value ) , 
129+                 ScalarStyle . SingleQuoted  or ScalarStyle . DoubleQuoted  or ScalarStyle . Literal  or ScalarStyle . Folded  or ScalarStyle . Any  =>  JsonValue . Create ( yaml . Value ) , 
130+                 _ =>  throw  new  ArgumentOutOfRangeException ( nameof ( yaml ) ) , 
131+             } ; 
132132        } 
133133
134134        private  static YamlScalarNode  ToYamlScalar ( this  JsonValue  val ) 
0 commit comments