예제 #1
0
            public LazyCosmosBinary(
                IJsonNavigator jsonNavigator,
                IJsonNavigatorNode jsonNavigatorNode)
            {
                JsonNodeType type = jsonNavigator.GetNodeType(jsonNavigatorNode);

                if (type != JsonNodeType.Binary)
                {
                    throw new ArgumentOutOfRangeException($"{nameof(jsonNavigatorNode)} must be a {JsonNodeType.Binary} node. Got {type} instead.");
                }

                this.jsonNavigator     = jsonNavigator;
                this.jsonNavigatorNode = jsonNavigatorNode;
                this.lazyBytes         = new Lazy <ReadOnlyMemory <byte> >(() =>
                {
                    if (!this.jsonNavigator.TryGetBufferedBinaryValue(
                            this.jsonNavigatorNode,
                            out ReadOnlyMemory <byte> bufferedBinaryValue))
                    {
                        bufferedBinaryValue = this.jsonNavigator.GetBinaryValue(
                            this.jsonNavigatorNode);
                    }

                    return(bufferedBinaryValue);
                });
            }