예제 #1
0
            public override IJsonReader CreateReader(IJsonNavigatorNode jsonNavigatorNode)
            {
                if (!(jsonNavigatorNode is JsonTextNavigatorNode jsonTextNavigatorNode))
                {
                    throw new ArgumentException($"{nameof(jsonNavigatorNode)} must be a {nameof(JsonTextNavigatorNode)}.");
                }

                ReadOnlyMemory <byte> buffer = jsonTextNavigatorNode switch
                {
                    LazyNode lazyNode => lazyNode.BufferedValue,
                    ArrayNode arrayNode => arrayNode.BufferedValue,
                    FalseNode falseNode => SingletonBuffers.False,
                    StringNodeBase stringNodeBase => stringNodeBase.BufferedValue.Memory,
                    NullNode nullNode => SingletonBuffers.Null,
                    NumberNode numberNode => numberNode.BufferedToken,
                    ObjectNode objectNode => objectNode.BufferedValue,
                    TrueNode trueNode => SingletonBuffers.True,
                    GuidNode guidNode => guidNode.BufferedToken,
                    BinaryNode binaryNode => binaryNode.BufferedToken,
                    IntegerNode intNode => intNode.BufferedToken,
                    FloatNode floatNode => floatNode.BufferedToken,
                                      _ => throw new ArgumentOutOfRangeException($"Unknown {nameof(JsonTextNavigatorNode)} type: {jsonTextNavigatorNode.GetType()}."),
                };

                return(JsonReader.Create(JsonSerializationFormat.Text, buffer));
            }
예제 #2
0
 private static ReadOnlyMemory <byte> GetNodeBuffer(JsonTextNavigatorNode jsonTextNavigatorNode)
 {
     return(jsonTextNavigatorNode switch
     {
         LazyNode lazyNode => lazyNode.BufferedValue,
         ArrayNode arrayNode => arrayNode.BufferedValue,
         FalseNode falseNode => SingletonBuffers.False,
         StringNodeBase stringNodeBase => stringNodeBase.BufferedValue.Memory,
         NullNode nullNode => SingletonBuffers.Null,
         NumberNode numberNode => numberNode.BufferedToken,
         ObjectNode objectNode => objectNode.BufferedValue,
         TrueNode trueNode => SingletonBuffers.True,
         GuidNode guidNode => guidNode.BufferedToken,
         BinaryNode binaryNode => binaryNode.BufferedToken,
         IntegerNode intNode => intNode.BufferedToken,
         FloatNode floatNode => floatNode.BufferedToken,
         _ => throw new ArgumentOutOfRangeException($"Unknown {nameof(JsonTextNavigatorNode)} type: {jsonTextNavigatorNode.GetType()}."),
     });