Ejemplo n.º 1
0
        public static void FromElement()
        {
            using (JsonDocument document = JsonDocument.Parse("[42]"))
            {
                JsonArray jArray = JsonArray.Create(document.RootElement);
                Assert.Equal(42, jArray[0].GetValue <int>());
            }

            using (JsonDocument document = JsonDocument.Parse("null"))
            {
                JsonArray jArray = JsonArray.Create(document.RootElement);
                Assert.Null(jArray);
            }
        }
Ejemplo n.º 2
0
        private void AddChild(JsonObject node, string propertyName, JsonElement element)
        {
            var options = new JsonNodeOptions
            {
                PropertyNameCaseInsensitive = Options.PropertyNameCaseInsensitive
            };

            JsonNode?childNode = element.ValueKind == JsonValueKind.Object
                ? JsonObject.Create(element, options)
                : element.ValueKind == JsonValueKind.Array
                    ? JsonArray.Create(element, options)
                    : JsonValue.Create(element, options);

            node[propertyName] = childNode;
        }
Ejemplo n.º 3
0
        public JsonObject ToJson()
        {
            var json = new JsonObject {
                { "Keys", new XNodeArray(Keys.Select(k => k.ToJson()).ToArray()) }
            };

            if (AttributesToGet != null)
            {
                json.Add("AttributesToGet", JsonArray.Create(AttributesToGet));
            }
            if (ConsistentRead)
            {
                json.Add("ConsistentRead", ConsistentRead);
            }

            return(json);
        }
Ejemplo n.º 4
0
        public JsonObject ToJson()
        {
            var json = new JsonObject {
                { "Keys", Keys.ToNodeList() }
            };

            if (AttributesToGet != null)
            {
                json.Add("AttributesToGet", JsonArray.Create(AttributesToGet));
            }

            if (ConsistentRead)
            {
                json.Add("ConsistentRead", ConsistentRead);
            }

            return(json);
        }
Ejemplo n.º 5
0
        public JsonObject ToJson()
        {
            var json = new JsonObject {
                { "TableName", TableName },
                { "Key", Key.ToJson() },
            };

            if (ConsistentRead)
            {
                json.Add("ConsistentRead", ConsistentRead);
            }
            if (ReturnConsumedCapacity)
            {
                json.Add("ReturnConsumedCapacity", "TOTAL");
            }
            if (AttributesToGet != null)
            {
                json.Add("AttributesToGet", JsonArray.Create(AttributesToGet));
            }

            return(json);
        }
Ejemplo n.º 6
0
 public static void FromElement_WrongNodeTypeThrows(string json)
 {
     using (JsonDocument document = JsonDocument.Parse(json))
         Assert.Throws <InvalidOperationException>(() => JsonArray.Create(document.RootElement));
 }