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)); }
/// <summary> /// Gets a string value from a node. /// </summary> /// <param name="stringNode">The <see cref="IJsonNavigatorNode"/> of the node to get the string value from.</param> /// <returns>The string value from the node.</returns> public override string GetStringValue(IJsonNavigatorNode stringNode) { if (stringNode == null) { throw new ArgumentNullException("stringNode"); } StringNodeBase stringValueNode = stringNode as StringNodeBase; if (stringValueNode == null) { throw new ArgumentException("stringNode must actually be a number node."); } return stringValueNode.Value; }
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()}."), });